[][src]Struct graph_rs_sdk::oauth::AccessToken

pub struct AccessToken { /* fields omitted */ }

OAuth 2.0 Access Token

Create a new AccessToken.

Example

let access_token = AccessToken::new("Bearer", 3600, "Read Read.Write", "ASODFIUJ34KJ;LADSK");

You can also get the claims using the claims() method as well as the remaining duration that the access token is valid using the elapsed() method.

Tokens returned for personal microsoft accounts that use legacy MSA are encrypted and cannot be parsed. This bearer token may still be valid but the jwt() method will return None. For more info see: Microsoft identity platform acccess tokens

For tokens where the JWT can be parsed the elapsed() method uses the exp field in the JWT's claims. If the claims do not contain an exp field or the token could not be parsed the elapsed() method uses the expires_in field returned in the response body to caculate the remaining time. These fields are only used once during initialization to set a timestamp for future expiration of the access token.

Example


// Claims
println!("{:#?}", access_token.claims());

// Duration left until expired.
println!("{:#?}", access_token.elapsed());

Implementations

impl AccessToken[src]

pub fn new(
    token_type: &str,
    expires_in: i64,
    scope: &str,
    access_token: &str
) -> AccessToken
[src]

pub fn set_token_type(&mut self, s: &str) -> &mut AccessToken[src]

Set the token type.

Example


let mut access_token = AccessToken::default();
access_token.set_token_type("Bearer");

pub fn set_expires_in(&mut self, expires_in: i64) -> &mut AccessToken[src]

Set the expies in time. This should usually be done in seconds.

Example


let mut access_token = AccessToken::default();
access_token.set_expires_in(3600);

pub fn set_scope(&mut self, s: &str) -> &mut AccessToken[src]

Set the scope.

Example


let mut access_token = AccessToken::default();
access_token.set_scope("Read Read.Write");

pub fn set_bearer_token(&mut self, s: &str) -> &mut AccessToken[src]

Set the access token.

Example


let mut access_token = AccessToken::default();
access_token.set_bearer_token("ASODFIUJ34KJ;LADSK");

pub fn set_refresh_token(&mut self, s: &str) -> &mut AccessToken[src]

Set the refresh token.

Example


let mut access_token = AccessToken::default();
access_token.set_refresh_token("#ASOD323U5342");

pub fn set_user_id(&mut self, s: &str) -> &mut AccessToken[src]

Set the user id.

Example


let mut access_token = AccessToken::default();
access_token.set_user_id("user_id");

pub fn set_id_token(&mut self, s: &str) -> &mut AccessToken[src]

Set the id token.

Example


let mut access_token = AccessToken::default();
access_token.set_id_token("id_token");

pub fn with_id_token(&mut self, id_token: IdToken)[src]

Set the id token.

Example


let mut access_token = AccessToken::default();
access_token.with_id_token(IdToken::new("id_token", "code", "state", "session_state"));

pub fn set_state(&mut self, s: &str) -> &mut AccessToken[src]

Set the state.

Example


let mut access_token = AccessToken::default();
access_token.set_state("state");

pub fn gen_timestamp(&mut self)[src]

Reset the access token timestmap.

Example


let mut access_token = AccessToken::default();
access_token.timestamp();
// The timestamp is in UTC.

pub fn token_type(&self) -> &str[src]

Get the token type.

Example


let mut access_token = AccessToken::default();
println!("{:#?}", access_token.token_type());

pub fn expires_in(&self) -> i64[src]

Set the user id.

Example


let mut access_token = AccessToken::default();
// This is the original amount that was set not the difference.
// To get the difference you can use access_token.elapsed().
println!("{:#?}", access_token.expires_in());

pub fn scopes(&self) -> Option<&String>[src]

Get the scopes.

Example


let mut access_token = AccessToken::default();
println!("{:#?}", access_token.scopes());

pub fn bearer_token(&self) -> &str[src]

Get the access token.

Example


let mut access_token = AccessToken::default();
println!("{:#?}", access_token.bearer_token());

pub fn user_id(&self) -> Option<String>[src]

Get the user id.

Example


let mut access_token = AccessToken::default();
println!("{:#?}", access_token.user_id());

pub fn refresh_token(self) -> Option<String>[src]

Get the refresh token.

Example


let mut access_token = AccessToken::default();
println!("{:#?}", access_token.refresh_token());

pub fn id_token(&self) -> Option<String>[src]

Get the id token.

Example


let mut access_token = AccessToken::default();
println!("{:#?}", access_token.id_token());

pub fn state(&self) -> Option<String>[src]

Get the state.

Example


let mut access_token = AccessToken::default();
println!("{:#?}", access_token.state());

pub fn timestamp(&self) -> Option<DateTime<Utc>>[src]

Get the timestamp.

Example


let mut access_token = AccessToken::default();
println!("{:#?}", access_token.timestamp());

pub fn is_expired(&self) -> bool[src]

Check whether the access token is expired. An access token is considerd expired when there is a negative difference between the timestamp set for the access token and the expires_in field.

Example


let mut access_token = AccessToken::default();
println!("{:#?}", access_token.is_expired());

pub fn elapsed(&self) -> Option<HumanTime>[src]

Get the time left in seconds until the access token expires. See the HumanTime crate. If you just need to know if the access token is expired then use the is_expired() message which returns a boolean true for the token has expired and false otherwise.

Example


let mut access_token = AccessToken::default();
println!("{:#?}", access_token.elapsed());

pub fn claims(&self) -> Option<Vec<Claim, Global>>[src]

pub fn jwt(&self) -> Option<&JsonWebToken>[src]

Trait Implementations

impl AsFile for AccessToken[src]

type Error = FromAsError

impl Clone for AccessToken[src]

impl Debug for AccessToken[src]

impl Default for AccessToken[src]

impl<'de> Deserialize<'de> for AccessToken[src]

impl Eq for AccessToken[src]

impl From<&'_ AccessToken> for Graph<BlockingHttpClient>[src]

impl From<&'_ AccessToken> for Graph<AsyncHttpClient>[src]

impl FromFile<AccessToken> for AccessToken[src]

type Error = FromAsError

impl PartialEq<AccessToken> for AccessToken[src]

impl Serialize for AccessToken[src]

impl StructuralEq for AccessToken[src]

impl StructuralPartialEq for AccessToken[src]

impl<'_> TryFrom<&'_ str> for AccessToken[src]

type Error = GraphFailure

The type returned in the event of a conversion error.

impl TryFrom<RequestBuilder> for AccessToken[src]

type Error = GraphFailure

The type returned in the event of a conversion error.

impl TryFrom<Response> for AccessToken[src]

type Error = GraphFailure

The type returned in the event of a conversion error.

impl TryFrom<Result<Response, Error>> for AccessToken[src]

type Error = GraphFailure

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.