This repository has been archived by the owner on Oct 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #303 from MindFlavor/issue/290/aad_refresh_token
Azure AAD: Exchange refresh token support
- Loading branch information
Showing
9 changed files
with
114 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub use crate::traits::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod refresh_token_response; | ||
pub use refresh_token_response::RefreshTokenResponse; |
67 changes: 67 additions & 0 deletions
67
azure_sdk_auth_aad/src/responses/refresh_token_response.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use crate::prelude::*; | ||
use oauth2::AccessToken; | ||
use std::convert::TryInto; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct RefreshTokenResponse { | ||
token_type: String, | ||
scopes: Vec<String>, | ||
expires_in: u64, | ||
ext_expires_in: u64, | ||
access_token: AccessToken, | ||
refresh_token: AccessToken, | ||
} | ||
|
||
impl TryInto<RefreshTokenResponse> for String { | ||
type Error = serde_json::Error; | ||
|
||
fn try_into(self) -> Result<RefreshTokenResponse, Self::Error> { | ||
// we use a temp struct to deserialize the scope into | ||
// the scopes vec at later time | ||
#[derive(Debug, Clone, Deserialize)] | ||
pub struct _RefreshTokenResponse<'a> { | ||
token_type: String, | ||
scope: &'a str, | ||
expires_in: u64, | ||
ext_expires_in: u64, | ||
access_token: AccessToken, | ||
refresh_token: AccessToken, | ||
} | ||
|
||
serde_json::from_str::<_RefreshTokenResponse>(&self).map(|rtr| RefreshTokenResponse { | ||
token_type: rtr.token_type, | ||
scopes: rtr.scope.split(' ').map(|s| s.to_owned()).collect(), | ||
expires_in: rtr.expires_in, | ||
ext_expires_in: rtr.ext_expires_in, | ||
access_token: rtr.access_token, | ||
refresh_token: rtr.refresh_token, | ||
}) | ||
} | ||
} | ||
|
||
impl BearerToken for RefreshTokenResponse { | ||
fn token_type(&self) -> &str { | ||
&self.token_type | ||
} | ||
fn scopes(&self) -> &[String] { | ||
&self.scopes | ||
} | ||
fn expires_in(&self) -> u64 { | ||
self.expires_in | ||
} | ||
fn access_token(&self) -> &AccessToken { | ||
&self.access_token | ||
} | ||
} | ||
|
||
impl RefreshToken for RefreshTokenResponse { | ||
fn refresh_token(&self) -> &AccessToken { | ||
&self.refresh_token | ||
} | ||
} | ||
|
||
impl ExtExpiresIn for RefreshTokenResponse { | ||
fn ext_expires_in(&self) -> u64 { | ||
self.ext_expires_in | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use oauth2::AccessToken; | ||
|
||
pub trait BearerToken { | ||
fn token_type(&self) -> &str; | ||
fn scopes(&self) -> &[String]; | ||
fn expires_in(&self) -> u64; | ||
fn access_token(&self) -> &AccessToken; | ||
} | ||
|
||
pub trait RefreshToken { | ||
fn refresh_token(&self) -> &AccessToken; | ||
} | ||
|
||
pub trait ExtExpiresIn { | ||
fn ext_expires_in(&self) -> u64; | ||
} |