-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
108 lines (80 loc) · 3.6 KB
/
example.py
File metadata and controls
108 lines (80 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/python
# $Id: example.py,v 1.6 2014/11/26 17:25:15 titus Exp $
#
# SecSign ID Api example in python.
#
# (c) 2014 SecSign Technologies Inc.
#
import time
from SecSignIDApi import SecSignIDApi
from SecSignIDApi import AuthSession
from SecSignIDApi import InputError
#
#
# Example how to retrieve an authentication session, ask its status and withdraw the authentication session.
#
#
#
# Create an instance of SecSignIDApi.
#
print("create new instance of SecSignIDApi.")
secSignIDApi = SecSignIDApi()
#
# The servicename and address is mandatory. It has to be send to the server.
# The value of servicename will be shown on the display of the smartphone. The user then can decide whether he accepts the authentication session shown on his mobile phone.
#
servicename = "Your Website Login";
serviceaddress = "http://www.yoursite.com/";
secsignid = "username";
#
# Get a auth session for the sepcified SecSign ID
#
# If secsignid is null or empty an exception is thrown.
# If servicename is null or empty an exception is thrown.
#
try:
authSession = secSignIDApi.requestAuthSession(secsignid, servicename, serviceaddress)
print("got authSession '" + str(authSession) + "'")
except InputError as e:
print("could not get an authentication session for SecSign ID '" + secsignid + "' : " + e.strerror)
exit(1)
#
# Get the auth session status
#
# If authSession is null or not an instance of AuthSession an exception is thrown
#
authSessionState = authSession.NOSTATE
try:
authSessionState = secSignIDApi.getAuthSessionState(authSession)
print("got auth session state: " + authSessionState);
except InputError as e:
print("could not get status for authentication session '" + str(authSession.authSessionID) + "' : " + e.strerror)
exit(1)
# If the script shall wait till the user has accepted the auth session or denied it, it has to ask the server frequently
secondsToWaitUntilNextCheck = 10
noError = True
while noError and (int(authSessionState) == AuthSession.PENDING or int(authSessionState) == AuthSession.FETCHED):
try:
authSessionState = secSignIDApi.getAuthSessionState(authSession);
print("auth session state: " + authSessionState)
if int(authSessionState) == AuthSession.PENDING or int(authSessionState) == AuthSession.FETCHED:
time.sleep(secondsToWaitUntilNextCheck)
except InputError as e:
print("could not get auth session status for auth session '" + authSession.authSessionID + "' : " + e.strerror)
noError = False;
if int(authSessionState) == authSession.AUTHENTICATED:
print("user has accepted the auth session '" + authSession.authSessionID + "'")
# release auth session to free resources serverside
secSignIDApi.releaseAuthSession(authSession)
print("auth session '" + authSession.authSessionID + "' was released.")
elif int(authSessionState) == authSession.DENIED:
print("user has denied the auth session '" + authSession.authSessionID + "'.")
authSessionState = secSignIDApi.cancelAuthSession(authSession); # after the auth session is successfully canceled it is not possible to inquire the status again
if authSessionState == authSession.CANCELED:
print("authentication session successfully cancelled...")
else:
print("auth session '" + authSession.authSessionID + "' has state " + authSessionState + ".")
authSessionState = secSignIDApi.cancelAuthSession(authSession); # after the auth session is successfully canceled it is not possible to inquire the status again
if int(authSessionState) == authSession.CANCELED:
print("authentication session successfully cancelled...")
### end