[][src]Struct graph_rs_sdk::oauth::OAuth

pub struct OAuth { /* fields omitted */ }

OAuth

OAuth client implementing the OAuth 2.0 and OpenID Connect protocols on Microsoft identity platform. This version is specifically meant for the Graph V1.0 and Beta API.

The client supports almost all OAuth 2.0 flows that Microsoft implements as well as the token and code flow specific to the OneDrive api.

The OAuth client is strict on what can be used for a specific OAuth flow. This is to ensure that the credentials used in requests include only information that is required or optional for that specific grant and not any other. Even if you accidently pass a value, such as a nonce, for a grant type that does not use it, any request that is made will not include the nonce regardless.

Disclaimer

Using this API for other resource owners besides Microsoft may work but functionality will more then likely be limited.

Example

use graph_oauth::oauth::OAuth;
let oauth = OAuth::new();

Implementations

impl OAuth[src]

pub fn new() -> OAuth[src]

Create a new OAuth instance.

Example

use graph_oauth::oauth::{OAuth, GrantType};

let mut oauth = OAuth::new();

pub fn insert<V>(&mut self, oac: OAuthCredential, value: V) -> &mut OAuth where
    V: ToString
[src]

Insert oauth credentials using the OAuthCredential enum. This method is used internally for each of the setter methods. Callers can optionally use this method to set credentials instead of the individual setter methods.

Example

oauth.insert(OAuthCredential::AuthorizeURL, "https://example.com");
assert!(oauth.contains(OAuthCredential::AuthorizeURL));
println!("{:#?}", oauth.get(OAuthCredential::AuthorizeURL));

pub fn entry<V>(&mut self, oac: OAuthCredential, value: V) -> &mut String where
    V: ToString
[src]

Insert and OAuth credential using the entry trait and returning the credential. This internally calls entry.(OAuthCredential).or_insret_with(value).

Example

let entry = oauth.entry(OAuthCredential::AuthorizeURL, "https://example.com");
assert_eq!(entry, "https://example.com")

pub fn get(&self, oac: OAuthCredential) -> Option<String>[src]

Get a previously set credential.

Example

let a = oauth.get(OAuthCredential::AuthorizeURL);

pub fn contains(&self, t: OAuthCredential) -> bool[src]

Check if an OAuth credential has already been set.

Example

println!("{:#?}", oauth.contains(OAuthCredential::Nonce));

pub fn contains_key(&self, key: &str) -> bool[src]

pub fn remove(&mut self, oac: OAuthCredential) -> &mut OAuth[src]

Remove a field from OAuth.

Example

oauth.client_id("client_id");

assert_eq!(oauth.contains(OAuthCredential::ClientId), true);
oauth.remove(OAuthCredential::ClientId);

assert_eq!(oauth.contains(OAuthCredential::ClientId), false);

pub fn client_id(&mut self, value: &str) -> &mut OAuth[src]

Set the client id for an OAuth request.

Example

oauth.client_id("client_id");

pub fn state(&mut self, value: &str) -> &mut OAuth[src]

Set the state for an OAuth request.

Example

oauth.state("1234");

pub fn client_secret(&mut self, value: &str) -> &mut OAuth[src]

Set the client secret for an OAuth request.

Example

oauth.client_secret("client_secret");

pub fn authorize_url(&mut self, value: &str) -> &mut OAuth[src]

Set the authorization URL.

Example

oauth.authorize_url("https://example.com/authorize");

pub fn access_token_url(&mut self, value: &str) -> &mut OAuth[src]

Set the access token url of a request for OAuth

Example

oauth.access_token_url("https://example.com/token");

pub fn refresh_token_url(&mut self, value: &str) -> &mut OAuth[src]

Set the refresh token url of a request for OAuth

Example

oauth.refresh_token_url("https://example.com/token");

pub fn redirect_uri(&mut self, value: &str) -> &mut OAuth[src]

Set the redirect url of a request

Example

oauth.redirect_uri("https://localhost:8888/redirect");

pub fn access_code(&mut self, value: &str) -> &mut OAuth[src]

Set the access code.

Example

oauth.access_code("LDSF[POK43");

pub fn response_mode(&mut self, value: &str) -> &mut OAuth[src]

Set the response mode.

Example

oauth.response_mode("query");

pub fn response_type(&mut self, value: &str) -> &mut OAuth[src]

Set the response type.

Example

oauth.response_type("token");

pub fn nonce(&mut self, value: &str) -> &mut OAuth[src]

Set the nonce.

Example


oauth.nonce("1234");

pub fn prompt(&mut self, value: &str) -> &mut OAuth[src]

Set the prompt for open id.

Example


oauth.prompt("login");

pub fn id_token(&mut self, value: IdToken) -> &mut OAuth[src]

Set id token for open id.

Example

oauth.id_token(IdToken::new("1345", "code", "state", "session_state"));

pub fn session_state(&mut self, value: &str) -> &mut OAuth[src]

Set the session state.

Example

oauth.session_state("session-state");

pub fn grant_type(&mut self, value: &str) -> &mut OAuth[src]

Set the grant_type.

Example

oauth.grant_type("token");

pub fn resource(&mut self, value: &str) -> &mut OAuth[src]

Set the resource.

Example

oauth.resource("resource");

pub fn code_verifier(&mut self, value: &str) -> &mut OAuth[src]

Set the code verifier.

Example

oauth.code_verifier("code_verifier");

pub fn domain_hint(&mut self, value: &str) -> &mut OAuth[src]

Set the domain hint.

Example

oauth.domain_hint("domain_hint");

pub fn code_challenge(&mut self, value: &str) -> &mut OAuth[src]

Set the code challenge.

Example

oauth.code_challenge("code_challenge");

pub fn code_challenge_method(&mut self, value: &str) -> &mut OAuth[src]

Set the code challenge method.

Example

oauth.code_challenge_method("code_challenge_method");

pub fn generate_sha256_challenge_and_verifier(
    &mut self
) -> Result<(), GraphFailure>
[src]

Generate a code challenge and code verifier for the authorization code grant flow using proof key for code exchange (PKCE) and SHA256.

This method automatically sets the code_verifier, code_challenge, and code_challenge_method fields.

For authorization, the code_challenge_method parameter in the request body is automatically set to 'S256'.

Internally this method uses the Rust ring cyrpto library to generate a secure random 32-octet sequence that is base64 URL encoded (no padding). This sequence is hashed using SHA256 and base64 URL encoded (no padding) resulting in a 43-octet URL safe string.

For more info on PKCE and entropy see: https://tools.ietf.org/html/rfc7636#section-7.1

Example


let mut oauth = OAuth::new();
oauth.generate_sha256_challenge_and_verifier();

println!("Code Challenge: {:#?}", oauth.get(OAuthCredential::CodeChallenge));
println!("Code Verifier: {:#?}", oauth.get(OAuthCredential::CodeVerifier));
println!("Code Challenge Method: {:#?}", oauth.get(OAuthCredential::CodeChallengeMethod));

pub fn login_hint(&mut self, value: &str) -> &mut OAuth[src]

Set the login hint.

Example

oauth.login_hint("login_hint");

pub fn client_assertion(&mut self, value: &str) -> &mut OAuth[src]

Set the client assertion.

Example

oauth.client_assertion("client_assertion");

pub fn client_assertion_type(&mut self, value: &str) -> &mut OAuth[src]

Set the client assertion type.

Example

oauth.client_assertion_type("client_assertion_type");

pub fn logout_url(&mut self, value: &str) -> &mut OAuth[src]

Set the url to send a post request that will log out the user.

Example

oauth.logout_url("https://example.com/logout?");

pub fn post_logout_redirect_uri(&mut self, value: &str) -> &mut OAuth[src]

Set the redirect uri that user will be redirected to after logging out.

Example

oauth.post_logout_redirect_uri("http://localhost:8080");

pub fn username(&mut self, value: &str) -> &mut OAuth[src]

Set the redirect uri that user will be redirected to after logging out.

Example

oauth.username("user");
assert!(oauth.contains(OAuthCredential::Username))

pub fn password(&mut self, value: &str) -> &mut OAuth[src]

Set the redirect uri that user will be redirected to after logging out.

Example

oauth.password("user");
assert!(oauth.contains(OAuthCredential::Password))

pub fn add_scope<T>(&mut self, scope: T) -> &mut OAuth where
    T: ToString
[src]

Add a scope' for the OAuth URL.

Example


oauth.add_scope("Sites.Read")
    .add_scope("Sites.ReadWrite")
    .add_scope("Sites.ReadWrite.All");
assert_eq!(oauth.join_scopes(" "), "Sites.Read Sites.ReadWrite Sites.ReadWrite.All");

pub fn get_scopes(&self) -> &BTreeSet<String>[src]

Get the scopes.

Example

let mut oauth = OAuth::new();
oauth.add_scope("Files.Read");
oauth.add_scope("Files.ReadWrite");

let scopes = oauth.get_scopes();
assert!(scopes.contains("Files.Read"));
assert!(scopes.contains("Files.ReadWrite"));

pub fn join_scopes(&self, sep: &str) -> String[src]

Join scopes.

Example


// the scopes take a separator just like Vec join.
 let s = oauth.join_scopes(" ");
println!("{:#?}", s);

pub fn extend_scopes<T, I>(&mut self, iter: I) -> &mut OAuth where
    T: ToString,
    I: IntoIterator<Item = T>, 
[src]

Extend scopes.

Example


let scopes1 = vec!["Files.Read", "Files.ReadWrite"];
oauth.extend_scopes(&scopes1);

assert_eq!(oauth.join_scopes(" "), "Files.Read Files.ReadWrite");

pub fn contains_scope<T>(&self, scope: T) -> bool where
    T: ToString
[src]

Check if OAuth contains a specific scope.

Example


oauth.add_scope("Files.Read");
assert_eq!(oauth.contains_scope("Files.Read"), true);

// Or using static scopes
oauth.add_scope("File.ReadWrite");
assert!(oauth.contains_scope("File.ReadWrite"));

pub fn remove_scope<T>(&mut self, scope: T) where
    T: AsRef<str>, 
[src]

Remove a previously added scope.

Example


oauth.add_scope("scope");
oauth.remove_scope("scope");

pub fn clear_scopes(&mut self)[src]

Remove all scopes.

Example


oauth.add_scope("Files.Read").add_scope("Files.ReadWrite");
assert_eq!("Files.Read Files.ReadWrite", oauth.join_scopes(" "));

oauth.clear_scopes();
assert!(oauth.get_scopes().is_empty());

pub fn access_token(&mut self, ac: AccessToken)[src]

Set the access token.

Example

use graph_oauth::oauth::OAuth;
use graph_oauth::oauth::AccessToken;
let mut oauth = OAuth::new();
let access_token = AccessToken::default();
oauth.access_token(access_token);

pub fn get_access_token(&self) -> Option<AccessToken>[src]

Get the access token.

Example

let access_token = oauth.get_access_token().unwrap();
println!("{:#?}", access_token);

pub fn get_refresh_token(&self) -> Result<String, GraphFailure>[src]

Get the refrsh token. This method returns the current refresh token stored in OAuth and does not make a request for a refresh token.

Example

let mut  access_token = AccessToken::default();
access_token.set_refresh_token("refresh_token");
oauth.access_token(access_token);

let refresh_token = oauth.get_refresh_token().unwrap();
println!("{:#?}", refresh_token);

pub fn build(&mut self) -> GrantSelector<AccessTokenGrant>[src]

pub fn build_async(&mut self) -> GrantSelector<AsyncAccessTokenGrant>[src]

pub fn v1_logout(&mut self) -> Result<Output, GraphFailure>[src]

Sign the user out using the OneDrive v1.0 endpoint.

Example

use graph_oauth::oauth::OAuth;
let mut oauth = OAuth::new();

oauth.v1_logout().unwrap();

pub fn v2_logout(&self) -> Result<Output, GraphFailure>[src]

Sign the user out using the OneDrive v2.0 endpoint.

Example

use graph_oauth::oauth::OAuth;
let mut oauth = OAuth::new();

oauth.v2_logout().unwrap();

impl OAuth[src]

pub fn params(
    &mut self,
    pairs: Vec<OAuthCredential, Global>
) -> Result<HashMap<String, String, RandomState>, GraphFailure>
[src]

pub fn encode_uri(
    &mut self,
    grant: GrantType,
    request_type: GrantRequest
) -> Result<String, GraphFailure>
[src]

Trait Implementations

impl AsFile for OAuth[src]

type Error = FromAsError

impl Clone for OAuth[src]

impl Debug for OAuth[src]

impl Default for OAuth[src]

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

impl Eq for OAuth[src]

impl<V> Extend<(OAuthCredential, V)> for OAuth where
    V: ToString
[src]

Extend the OAuth credentials.

Example

let mut map: HashMap<OAuthCredential, &str> = HashMap::new();
map.insert(OAuthCredential::ClientId, "client_id");
map.insert(OAuthCredential::ClientSecret, "client_secret");

oauth.extend(map);

impl From<AccessTokenGrant> for OAuth[src]

impl From<ImplicitGrant> for OAuth[src]

impl FromFile<OAuth> for OAuth[src]

type Error = FromAsError

impl PartialEq<OAuth> for OAuth[src]

impl Serialize for OAuth[src]

impl StructuralEq for OAuth[src]

impl StructuralPartialEq for OAuth[src]

impl TryFrom<&'_ OAuth> for Graph<BlockingHttpClient>[src]

type Error = GraphFailure

The type returned in the event of a conversion error.

impl TryFrom<&'_ OAuth> for Graph<AsyncHttpClient>[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.