@@ -64,7 +64,6 @@ def do_response(
64
64
client_id : Optional [str ] = "" ,
65
65
** kwargs ,
66
66
) -> dict :
67
-
68
67
if "error" in kwargs and kwargs ["error" ]:
69
68
return Endpoint .do_response (self , response_args , request , ** kwargs )
70
69
@@ -126,44 +125,35 @@ def process_request(self, request=None, **kwargs):
126
125
return self .error_cls (error = "invalid_token" , error_description = "Invalid Token" )
127
126
128
127
_grant = _session_info ["grant" ]
129
- token = _grant .get_token (request ["access_token" ])
130
- # should be an access token
131
- if token and token .token_class != "access_token" :
132
- return self .error_cls (error = "invalid_token" , error_description = "Wrong type of token" )
128
+ access_token = _grant .get_token (request ["access_token" ])
133
129
134
- # And it should be valid
135
- if token . is_active () is False :
130
+ # there must be a token
131
+ if not access_token :
136
132
return self .error_cls (error = "invalid_token" , error_description = "Invalid Token" )
137
133
138
- allowed = True
139
- _auth_event = _grant .authentication_event
140
- # if the authentication is still active or offline_access is granted.
141
- if not _auth_event ["valid_until" ] >= utc_time_sans_frac ():
142
- logger .debug (
143
- "authentication not valid: {} > {}" .format (
144
- datetime .fromtimestamp (_auth_event ["valid_until" ]),
145
- datetime .fromtimestamp (utc_time_sans_frac ()),
146
- )
147
- )
148
- allowed = False
134
+ # the token must be an access_token
135
+ if access_token .token_class != "access_token" :
136
+ return self .error_cls (error = "invalid_token" , error_description = "Wrong type of token" )
149
137
150
- # This has to be made more finegrained.
151
- # if "offline_access" in session["authn_req"]["scope"]:
152
- # pass
138
+ # the access_token must be valid
139
+ if access_token .is_active () is False :
140
+ return self .error_cls (error = "invalid_token" , error_description = "Invalid Token" )
141
+
142
+ # the access_token must contain the openid scope
143
+ if "openid" not in access_token .scope :
144
+ return self .error_cls (error = "invalid_token" , error_description = "Invalid Token" )
153
145
154
146
_cntxt = self .upstream_get ("context" )
155
- if allowed :
156
- _claims_restriction = _cntxt .claims_interface .get_claims (
157
- _session_info ["branch_id" ], scopes = token .scope , claims_release_point = "userinfo"
158
- )
159
- info = _cntxt .claims_interface .get_user_claims (
160
- _session_info ["user_id" ],
161
- claims_restriction = _claims_restriction ,
162
- client_id = _session_info ["client_id" ]
163
- )
164
- info ["sub" ] = _grant .sub
165
- if _grant .add_acr_value ("userinfo" ):
166
- info ["acr" ] = _grant .authentication_event ["authn_info" ]
147
+ _claims_restriction = _cntxt .claims_interface .get_claims (
148
+ _session_info ["branch_id" ], scopes = access_token .scope , claims_release_point = "userinfo"
149
+ )
150
+ info = _cntxt .claims_interface .get_user_claims (
151
+ _session_info ["user_id" ], claims_restriction = _claims_restriction ,
152
+ client_id = _session_info ["client_id" ]
153
+ )
154
+ info ["sub" ] = _grant .sub
155
+ if _grant .add_acr_value ("userinfo" ):
156
+ info ["acr" ] = _grant .authentication_event ["authn_info" ]
167
157
168
158
extra_claims = kwargs .get ("extra_claims" )
169
159
if extra_claims :
@@ -173,7 +163,7 @@ def process_request(self, request=None, **kwargs):
173
163
self .config ["policy" ] = _cntxt .cdb [request ["client_id" ]]["userinfo" ]["policy" ]
174
164
175
165
if "policy" in self .config :
176
- info = self ._enforce_policy (request , info , token , self .config )
166
+ info = self ._enforce_policy (request , info , access_token , self .config )
177
167
178
168
return {"response_args" : info , "client_id" : _session_info ["client_id" ]}
179
169
@@ -213,7 +203,7 @@ def parse_request(self, request, http_info=None, **kwargs):
213
203
def _enforce_policy (self , request , response_info , token , config ):
214
204
policy = config ["policy" ]
215
205
callable = policy ["function" ]
216
- kwargs = policy .get ("kwargs" , {})
206
+ kwargs = policy .get ("kwargs" ) or {}
217
207
218
208
if isinstance (callable , str ):
219
209
try :
0 commit comments