@@ -190,6 +190,75 @@ fn test_exchange_client_credentials_with_json_response() {
190
190
assert_eq ! ( None , token. refresh_token) ;
191
191
}
192
192
193
+ #[ test]
194
+ fn test_exchange_refresh_token_with_form_response ( ) {
195
+ let mock = mock ( "POST" , "/token" )
196
+ . match_body ( "grant_type=refresh_token&refresh_token=ccc&client_id=aaa&client_secret=bbb" )
197
+ . with_body ( "access_token=12%2F34&token_type=bearer&scope=read,write" )
198
+ . create ( ) ;
199
+
200
+ let config = Config :: new ( "aaa" , "bbb" , "http://example.com/auth" , & ( SERVER_URL . to_string ( ) + "/token" ) ) ;
201
+ let token = config. exchange_refresh_token ( "ccc" ) ;
202
+
203
+ mock. assert ( ) ;
204
+
205
+ assert ! ( token. is_ok( ) ) ;
206
+
207
+ let token = token. unwrap ( ) ;
208
+ assert_eq ! ( "12/34" , token. access_token) ;
209
+ assert_eq ! ( "bearer" , token. token_type) ;
210
+ assert_eq ! ( vec![ "read" . to_string( ) , "write" . to_string( ) ] , token. scopes) ;
211
+ assert_eq ! ( None , token. expires_in) ;
212
+ assert_eq ! ( None , token. refresh_token) ;
213
+ }
214
+
215
+ #[ test]
216
+ fn test_exchange_refresh_token_with_basic_auth ( ) {
217
+ let mock = mock ( "POST" , "/token" )
218
+ . match_header ( "Authorization" , "Basic YWFhOmJiYg==" ) // base64("aaa:bbb")
219
+ . match_body ( "grant_type=refresh_token&refresh_token=ccc" )
220
+ . with_body ( "access_token=12%2F34&token_type=bearer&scope=read,write" )
221
+ . create ( ) ;
222
+
223
+ let mut config = Config :: new ( "aaa" , "bbb" , "http://example.com/auth" , & ( SERVER_URL . to_string ( ) + "/token" ) ) ;
224
+ config = config. set_auth_type ( oauth2:: AuthType :: BasicAuth ) ;
225
+ let token = config. exchange_refresh_token ( "ccc" ) ;
226
+
227
+ mock. assert ( ) ;
228
+
229
+ assert ! ( token. is_ok( ) ) ;
230
+
231
+ let token = token. unwrap ( ) ;
232
+ assert_eq ! ( "12/34" , token. access_token) ;
233
+ assert_eq ! ( "bearer" , token. token_type) ;
234
+ assert_eq ! ( vec![ "read" . to_string( ) , "write" . to_string( ) ] , token. scopes) ;
235
+ assert_eq ! ( None , token. expires_in) ;
236
+ assert_eq ! ( None , token. refresh_token) ;
237
+ }
238
+
239
+ #[ test]
240
+ fn test_exchange_refresh_token_with_json_response ( ) {
241
+ let mock = mock ( "POST" , "/token" )
242
+ . match_body ( "grant_type=refresh_token&refresh_token=ccc&client_id=aaa&client_secret=bbb" )
243
+ . with_header ( "content-type" , "application/json" )
244
+ . with_body ( "{\" access_token\" : \" 12/34\" , \" token_type\" : \" bearer\" , \" scopes\" : [\" read\" , \" write\" ]}" )
245
+ . create ( ) ;
246
+
247
+ let config = Config :: new ( "aaa" , "bbb" , "http://example.com/auth" , & ( SERVER_URL . to_string ( ) + "/token" ) ) ;
248
+ let token = config. exchange_refresh_token ( "ccc" ) ;
249
+
250
+ mock. assert ( ) ;
251
+
252
+ assert ! ( token. is_ok( ) ) ;
253
+
254
+ let token = token. unwrap ( ) ;
255
+ assert_eq ! ( "12/34" , token. access_token) ;
256
+ assert_eq ! ( "bearer" , token. token_type) ;
257
+ assert_eq ! ( vec![ "read" . to_string( ) , "write" . to_string( ) ] , token. scopes) ;
258
+ assert_eq ! ( None , token. expires_in) ;
259
+ assert_eq ! ( None , token. refresh_token) ;
260
+ }
261
+
193
262
#[ test]
194
263
fn test_exchange_password_with_form_response ( ) {
195
264
let mock = mock ( "POST" , "/token" )
0 commit comments