66from cryptojwt .jwk import rsa_load
77
88from oidcmsg .key_bundle import KeyBundle
9- from oidcmsg .oauth2 import AccessTokenRequest , AuthorizationResponse
9+ from oidcmsg .oauth2 import AccessTokenRequest
1010from oidcmsg .oauth2 import AccessTokenResponse
1111from oidcmsg .oauth2 import AuthorizationRequest
12+ from oidcmsg .oauth2 import AuthorizationResponse
1213from oidcmsg .oauth2 import RefreshAccessTokenRequest
1314from oidcmsg .oidc import IdToken
1415from oidcmsg .time_util import utc_time_sans_frac
1516
16- from oidcservice .client_auth import CLIENT_AUTHN_METHOD
1717from oidcservice .state_interface import State
1818
1919from oidcrp .oidc import RP
2020
2121sys .path .insert (0 , '.' )
2222
2323_dirname = os .path .dirname (os .path .abspath (__file__ ))
24- BASE_PATH = os .path .join (_dirname , "data" , " keys" )
24+ BASE_PATH = os .path .join (_dirname , "keys" )
2525
2626_key = rsa_load (os .path .join (BASE_PATH , "rsa.key" ))
2727KC_RSA = KeyBundle ({"key" : _key , "kty" : "RSA" , "use" : "sig" })
@@ -52,14 +52,16 @@ def create_client(self):
5252 'redirect_uris' : ['https://example.com/cli/authz_cb' ],
5353 'client_id' : 'client_1' ,
5454 'client_secret' : 'abcdefghijklmnop' ,
55- }
55+ }
5656 self .client = RP (DB (), config = conf )
57- self .client .state_db . set ( 'ABCDE ' , State ( iss = 'issuer' ). to_json () )
57+ self .client .session_interface . create_state ( 'issuer ' , 'ABCDE' )
5858
5959 def test_construct_authorization_request (self ):
60- req_args = {'state' : 'ABCDE' ,
61- 'redirect_uri' : 'https://example.com/auth_cb' ,
62- 'response_type' : ['code' ]}
60+ req_args = {
61+ 'state' : 'ABCDE' ,
62+ 'redirect_uri' : 'https://example.com/auth_cb' ,
63+ 'response_type' : ['code' ]
64+ }
6365 msg = self .client .service ['authorization' ].construct (
6466 request_args = req_args )
6567 assert isinstance (msg , AuthorizationRequest )
@@ -69,11 +71,14 @@ def test_construct_accesstoken_request(self):
6971 auth_request = AuthorizationRequest (
7072 redirect_uri = 'https://example.com/cli/authz_cb' ,
7173 state = 'state'
72- )
74+ )
75+ self .client .session_interface .store_item (auth_request , 'auth_request' ,
76+ 'ABCDE' )
77+
7378 auth_response = AuthorizationResponse (code = 'access_code' )
74- _state = State (auth_response = auth_response . to_json () ,
75- auth_request = auth_request . to_json () )
76- self . client . state_db . set ( 'ABCDE' , _state . to_json ())
79+ self . client . session_interface . store_item (auth_response , ' auth_response' ,
80+ 'ABCDE' )
81+
7782 # Bind access code to state
7883 req_args = {}
7984 msg = self .client .service ['accesstoken' ].construct (
@@ -84,44 +89,52 @@ def test_construct_accesstoken_request(self):
8489 'client_secret' : 'abcdefghijklmnop' ,
8590 'grant_type' : 'authorization_code' ,
8691 'redirect_uri' : 'https://example.com/cli/authz_cb' ,
87- 'state' : 'state' }
92+ 'state' : 'state'
93+ }
8894
8995 def test_construct_refresh_token_request (self ):
9096 auth_request = AuthorizationRequest (
9197 redirect_uri = 'https://example.com/cli/authz_cb' ,
9298 state = 'state'
93- )
99+ )
100+ self .client .session_interface .store_item (auth_request , 'auth_request' ,
101+ 'ABCDE' )
94102 auth_response = AuthorizationResponse (code = 'access_code' )
103+ self .client .session_interface .store_item (auth_response , 'auth_response' ,
104+ 'ABCDE' )
95105 token_response = AccessTokenResponse (refresh_token = "refresh_with_me" ,
96106 access_token = "access" )
97- _state = State (auth_response = auth_response .to_json (),
98- auth_request = auth_request .to_json (),
99- token_response = token_response .to_json ())
100-
101- self .client .state_db .set ('ABCDE' , _state .to_json ())
107+ self .client .session_interface .store_item (token_response ,
108+ 'token_response' , 'ABCDE' )
102109
103110 req_args = {}
104111 msg = self .client .service ['refresh_token' ].construct (
105112 request_args = req_args , state = 'ABCDE' )
106113 assert isinstance (msg , RefreshAccessTokenRequest )
107- assert msg .to_dict () == {'client_id' : 'client_1' ,
108- 'client_secret' : 'abcdefghijklmnop' ,
109- 'grant_type' : 'refresh_token' ,
110- 'refresh_token' : 'refresh_with_me' }
114+ assert msg .to_dict () == {
115+ 'client_id' : 'client_1' ,
116+ 'client_secret' : 'abcdefghijklmnop' ,
117+ 'grant_type' : 'refresh_token' ,
118+ 'refresh_token' : 'refresh_with_me'
119+ }
111120
112121 def test_do_userinfo_request_init (self ):
113122 auth_request = AuthorizationRequest (
114123 redirect_uri = 'https://example.com/cli/authz_cb' ,
115124 state = 'state'
116- )
125+ )
126+ self .client .session_interface .store_item (auth_request , 'auth_request' ,
127+ 'ABCDE' )
117128 auth_response = AuthorizationResponse (code = 'access_code' )
129+
130+ self .client .session_interface .store_item (auth_response , 'auth_response' ,
131+ 'ABCDE' )
132+
118133 token_response = AccessTokenResponse (refresh_token = "refresh_with_me" ,
119134 access_token = "access" )
120- _state = State (auth_response = auth_response .to_json (),
121- auth_request = auth_request .to_json (),
122- token_response = token_response .to_json ())
123-
124- self .client .state_db .set ('ABCDE' , _state .to_json ())
135+ self .client .session_interface .store_item (token_response ,
136+ 'token_response' ,
137+ 'ABCDE' )
125138
126139 _srv = self .client .service ['userinfo' ]
127140 _srv .endpoint = "https://example.com/userinfo"
0 commit comments