66from cryptojwt import JWT
77from cryptojwt import as_unicode
88from cryptojwt .utils import as_bytes
9+ from oidcmsg .oidc import AccessTokenRequest
10+
11+ from oidcendpoint .oidc .token_coop import TokenCoop
12+
913from oidcendpoint .client_authn import ClientSecretPost
1014from oidcendpoint .client_authn import UnknownOrNoAuthnMethod
1115from oidcendpoint .client_authn import WrongAuthnMethod
6569 response_type = "code id_token" ,
6670)
6771
72+ TOKEN_REQ = AccessTokenRequest (
73+ client_id = "client_1" ,
74+ redirect_uri = "https://example.com/cb" ,
75+ state = "STATE" ,
76+ grant_type = "authorization_code" ,
77+ client_secret = "hemligt" ,
78+ )
79+
80+ TOKEN_REQ_DICT = TOKEN_REQ .to_dict ()
81+
6882BASEDIR = os .path .abspath (os .path .dirname (__file__ ))
6983
7084
@@ -98,6 +112,18 @@ def create_endpoint(self):
98112 "client_authn_method" : {"client_secret_post" : ClientSecretPost },
99113 },
100114 },
115+ "token" : {
116+ "path" : "token" ,
117+ "class" : TokenCoop ,
118+ "kwargs" : {
119+ "client_authn_method" : [
120+ "client_secret_basic" ,
121+ "client_secret_post" ,
122+ "client_secret_jwt" ,
123+ "private_key_jwt" ,
124+ ]
125+ },
126+ },
101127 },
102128 "authentication" : {
103129 "anon" : {
@@ -127,6 +153,7 @@ def create_endpoint(self):
127153 endpoint_context .issuer ,
128154 )
129155 self .introspection_endpoint = endpoint_context .endpoint ["introspection" ]
156+ self .token_endpoint = endpoint_context .endpoint ["token" ]
130157
131158 def _create_jwt (self , uid , lifetime = 0 , with_jti = False ):
132159 _jwt = JWT (
@@ -237,4 +264,33 @@ def test_do_response_no_token(self):
237264 }
238265 )
239266 _resp = self .introspection_endpoint .process_request (_req )
240- assert "error" in _resp
267+ assert "error" in _resp
268+
269+ def test_access_token (self ):
270+ _context = self .introspection_endpoint .endpoint_context
271+
272+ session_id = setup_session (
273+ _context ,
274+ AUTH_REQ ,
275+ uid = "user" ,
276+ acr = INTERNETPROTOCOLPASSWORD ,
277+ )
278+ _token_request = TOKEN_REQ_DICT .copy ()
279+ _token_request ["code" ] = _context .sdb [session_id ]["code" ]
280+ _context .sdb .update (session_id , user = "diana" )
281+
282+ _req = self .token_endpoint .parse_request (_token_request )
283+ _resp = self .token_endpoint .process_request (request = _req )
284+
285+ _req = self .introspection_endpoint .parse_request (
286+ {
287+ "token" : _resp ["response_args" ]["access_token" ],
288+ "client_id" : "client_1" ,
289+ "client_secret" : _context .cdb ["client_1" ]["client_secret" ],
290+ }
291+ )
292+ _resp = self .introspection_endpoint .process_request (_req )
293+ _resp_args = _resp ["response_args" ]
294+ assert "sub" in _resp_args
295+ assert _resp_args ["active" ]
296+ assert _resp_args ["scope" ] == "openid"
0 commit comments