mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-02-23 15:50:00 +01:00
@@ -123,12 +123,21 @@ where
|
||||
Some(app_secret),
|
||||
) => {
|
||||
// token is expired but has a refresh token.
|
||||
let token_info = RefreshFlow::refresh_token(
|
||||
let token_info_result = RefreshFlow::refresh_token(
|
||||
&self.inner.hyper_client,
|
||||
app_secret,
|
||||
&refresh_token,
|
||||
)
|
||||
.await?;
|
||||
.await;
|
||||
let token_info = if let Ok(token_info) = token_info_result {
|
||||
token_info
|
||||
} else {
|
||||
// token refresh failed.
|
||||
self.inner
|
||||
.auth_flow
|
||||
.token(&self.inner.hyper_client, scopes)
|
||||
.await?
|
||||
};
|
||||
self.inner
|
||||
.storage
|
||||
.set(hashed_scopes, token_info.clone())
|
||||
|
||||
@@ -446,6 +446,8 @@ async fn test_refresh() {
|
||||
.expect("failed to get token");
|
||||
assert_eq!("accesstoken3", tok.as_str());
|
||||
|
||||
// Refresh fails, but renewing the token succeeds.
|
||||
// PR #165
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method_path("POST", "/token"),
|
||||
@@ -458,18 +460,26 @@ async fn test_refresh() {
|
||||
"error": "invalid_request",
|
||||
}))),
|
||||
);
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method_path("POST", "/token"),
|
||||
request::body(url_decoded(all_of![
|
||||
contains(("code", "authorizationcode")),
|
||||
contains(("client_id", matches("^9022167"))),
|
||||
]))
|
||||
])
|
||||
.respond_with(json_encoded(serde_json::json!({
|
||||
"access_token": "accesstoken",
|
||||
"refresh_token": "refreshtoken",
|
||||
"token_type": "Bearer",
|
||||
"expires_in": 59,
|
||||
}))),
|
||||
);
|
||||
|
||||
let tok_err = auth
|
||||
.token(&["https://googleapis.com/some/scope"])
|
||||
.await
|
||||
.expect_err("token refresh succeeded unexpectedly");
|
||||
match tok_err {
|
||||
Error::AuthError(AuthError {
|
||||
error: AuthErrorCode::InvalidRequest,
|
||||
..
|
||||
}) => {}
|
||||
e => panic!("unexpected error on refresh: {:?}", e),
|
||||
}
|
||||
.await;
|
||||
assert!(tok_err.is_ok());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
Reference in New Issue
Block a user