@@ -37,7 +37,8 @@ def __init__(self, config, *args, **kwargs):
37
37
38
38
def _handle_al_response (self , context ):
39
39
"""
40
- Endpoint for handling account linking service response
40
+ Endpoint for handling account linking service response. When getting here
41
+ user might have approved or rejected linking their account
41
42
42
43
:type context: satosa.context.Context
43
44
:rtype: satosa.response.Response
@@ -47,7 +48,9 @@ def _handle_al_response(self, context):
47
48
"""
48
49
saved_state = context .state [self .name ]
49
50
internal_response = InternalResponse .from_dict (saved_state )
50
- status_code , message = self ._get_uuid (context , internal_response .auth_info .issuer , internal_response .user_id )
51
+
52
+ #user_id here is the linked id , not the facebook one, Figure out what to do
53
+ status_code , message = self ._get_uuid (context , internal_response .auth_info .issuer , internal_response .attributes ['issuer_user_id' ])
51
54
52
55
if status_code == 200 :
53
56
satosa_logging (logger , logging .INFO , "issuer/id pair is linked in AL service" ,
@@ -59,7 +62,13 @@ def _handle_al_response(self, context):
59
62
del context .state [self .name ]
60
63
return super ().process (context , internal_response )
61
64
else :
62
- raise SATOSAAuthenticationError (context .state , "Could not link account for user" )
65
+ # User selected not to link their accounts, so the internal.response.user_id is based on the
66
+ # issuers id/sub which is fine
67
+ satosa_logging (logger , logging .INFO , "User selected to not link their identity in AL service" ,
68
+ context .state )
69
+ del context .state [self .name ]
70
+ return super ().process (context , internal_response )
71
+
63
72
64
73
def process (self , context , internal_response ):
65
74
"""
@@ -72,42 +81,32 @@ def process(self, context, internal_response):
72
81
:param context:
73
82
:param internal_response:
74
83
:return: response
84
+ :
75
85
"""
76
86
77
87
status_code , message = self ._get_uuid (context , internal_response .auth_info .issuer , internal_response .user_id )
78
88
89
+ data = {
90
+ "issuer" : internal_response .auth_info .issuer ,
91
+ "redirect_endpoint" : "%s/account_linking%s" % (self .base_url , self .endpoint )
92
+ }
93
+
94
+ # Store the issuer user_id/sub because we'll need it in handle_al_response
95
+ internal_response .attributes ['issuer_user_id' ] = internal_response .user_id
79
96
if status_code == 200 :
80
97
satosa_logging (logger , logging .INFO , "issuer/id pair is linked in AL service" ,
81
98
context .state )
82
99
internal_response .user_id = message
100
+ data ['user_id' ] = message
83
101
if self .id_to_attr :
84
102
internal_response .attributes [id_to_attr ] = [message ]
85
- try :
86
- del context .state [self .name ]
87
- except KeyError :
88
- pass
89
- return super ().process (context , internal_response )
90
-
91
- return self ._approve_new_id (context , internal_response , message )
92
-
93
- def _approve_new_id (self , context , internal_response , ticket ):
94
- """
95
- Redirect the user to approve the new id
96
-
97
- :type context: satosa.context.Context
98
- :type internal_response: satosa.internal_data.InternalResponse
99
- :type ticket: str
100
- :rtype: satosa.response.Redirect
101
-
102
- :param context: The current context
103
- :param internal_response: The internal response
104
- :param ticket: The ticket given by the al service
105
- :return: A redirect to approve the new id linking
106
- """
107
- satosa_logging (logger , logging .INFO , "A new ID must be linked by the AL service" ,
108
- context .state )
103
+ else :
104
+ satosa_logging (logger , logging .INFO , "issuer/id pair is not linked in AL service. Got a ticket" ,
105
+ context .state )
106
+ data ['ticket' ] = message
107
+ jws = JWS (json .dumps (data ), alg = self .signing_key .alg ).sign_compact ([self .signing_key ])
109
108
context .state [self .name ] = internal_response .to_dict ()
110
- return Redirect ("%s/%s" % (self .redirect_url , ticket ))
109
+ return Redirect ("%s/%s" % (self .redirect_url , jws ))
111
110
112
111
def _get_uuid (self , context , issuer , id ):
113
112
"""
@@ -136,7 +135,7 @@ def _get_uuid(self, context, issuer, id):
136
135
try :
137
136
request = "{}/get_id?jwt={}" .format (self .api_url , jws )
138
137
response = requests .get (request )
139
- except requests . ConnectionError as con_exc :
138
+ except Exception as con_exc :
140
139
msg = "Could not connect to account linking service"
141
140
satosa_logging (logger , logging .CRITICAL , msg , context .state , exc_info = True )
142
141
raise SATOSAAuthenticationError (context .state , msg ) from con_exc
0 commit comments