@@ -125,18 +125,27 @@ def process_request(self, request=None, **kwargs):
125125 return self .error_cls (error = "invalid_token" , error_description = "Invalid Token" )
126126
127127 _grant = _session_info ["grant" ]
128- token = _grant .get_token (request ["access_token" ])
129- # should be an access token
130- if token and token .token_class != "access_token" :
128+ access_token = _grant .get_token (request ["access_token" ])
129+
130+ # there must be a token
131+ if not access_token :
132+ return self .error_cls (error = "invalid_token" , error_description = "Invalid Token" )
133+
134+ # the token must be an access_token
135+ if access_token .token_class != "access_token" :
131136 return self .error_cls (error = "invalid_token" , error_description = "Wrong type of token" )
132137
133- # And it should be valid
134- if token .is_active () is False :
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 :
135144 return self .error_cls (error = "invalid_token" , error_description = "Invalid Token" )
136145
137146 _cntxt = self .upstream_get ("context" )
138147 _claims_restriction = _cntxt .claims_interface .get_claims (
139- _session_info ["branch_id" ], scopes = token .scope , claims_release_point = "userinfo"
148+ _session_info ["branch_id" ], scopes = access_token .scope , claims_release_point = "userinfo"
140149 )
141150 info = _cntxt .claims_interface .get_user_claims (
142151 _session_info ["user_id" ], claims_restriction = _claims_restriction
@@ -153,7 +162,7 @@ def process_request(self, request=None, **kwargs):
153162 self .config ["policy" ] = _cntxt .cdb [request ["client_id" ]]["userinfo" ]["policy" ]
154163
155164 if "policy" in self .config :
156- info = self ._enforce_policy (request , info , token , self .config )
165+ info = self ._enforce_policy (request , info , access_token , self .config )
157166
158167 return {"response_args" : info , "client_id" : _session_info ["client_id" ]}
159168
0 commit comments