Struct graph_oauth::extensions::AuthSerializer

source ·
pub struct AuthSerializer { /* private fields */ }
Expand description

Serializer for query/x-www-form-urlencoded OAuth requests.

OAuth Serializer for query/form serialization that supports the OAuth 2.0 and OpenID Connect protocols on Microsoft identity platform.

§Example

use graph_oauth::extensions::AuthSerializer;
let oauth = AuthSerializer::new();

Implementations§

source§

impl AuthSerializer

source

pub fn new() -> AuthSerializer

Create a new OAuth instance.

§Example
use graph_oauth::extensions::AuthSerializer;

let mut oauth = AuthSerializer::new();
source

pub fn insert<V: ToString>( &mut self, oac: AuthParameter, value: V ) -> &mut AuthSerializer

Insert oauth credentials using the OAuthParameter 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(AuthParameter::AuthorizationCode, "code");
assert!(oauth.contains(AuthParameter::AuthorizationCode));
println!("{:#?}", oauth.get(AuthParameter::AuthorizationCode));
source

pub fn entry_with<V: ToString>( &mut self, oac: AuthParameter, value: V ) -> &mut String

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

§Example
let entry = oauth.entry_with(AuthParameter::AuthorizationCode, "code");
assert_eq!(entry, "code")
source

pub fn entry<V: ToString>( &mut self, oac: AuthParameter ) -> Entry<'_, String, String>

A view into a single entry in a map, which may either be vacant or occupied.

This enum is constructed from the entry method on BTreeMap.

source

pub fn get(&self, oac: AuthParameter) -> Option<String>

Get a previously set credential.

§Example
oauth.authorization_code("code");
let code = oauth.get(AuthParameter::AuthorizationCode);
assert_eq!("code", code.unwrap().as_str());
source

pub fn contains(&self, t: AuthParameter) -> bool

Check if an OAuth credential has already been set.

§Example
println!("{:#?}", oauth.contains(AuthParameter::Nonce));
source

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

source

pub fn remove(&mut self, oac: AuthParameter) -> &mut AuthSerializer

Remove a field from OAuth.

§Example
oauth.client_id("client_id");

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

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

pub fn client_id(&mut self, value: &str) -> &mut AuthSerializer

Set the client id for an OAuth request.

§Example
oauth.client_id("client_id");
source

pub fn state(&mut self, value: &str) -> &mut AuthSerializer

Set the state for an OAuth request.

§Example
oauth.state("1234");
source

pub fn client_secret(&mut self, value: &str) -> &mut AuthSerializer

Set the client secret for an OAuth request.

§Example
oauth.client_secret("client_secret");
source

pub fn redirect_uri(&mut self, value: &str) -> &mut AuthSerializer

Set the redirect url of a request

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

pub fn authorization_code(&mut self, value: &str) -> &mut AuthSerializer

Set the access code.

§Example
serializer.authorization_code("LDSF[POK43");
source

pub fn response_mode(&mut self, value: &str) -> &mut AuthSerializer

Set the response mode.

§Example
serializer.response_mode("query");
source

pub fn response_type<T: ToString>(&mut self, value: T) -> &mut AuthSerializer

Set the response type.

§Example
oauth.response_type("token");
source

pub fn response_types( &mut self, value: Iter<'_, ResponseType> ) -> &mut AuthSerializer

source

pub fn nonce(&mut self, value: &str) -> &mut AuthSerializer

Set the nonce.

§Example

oauth.nonce("1234");
source

pub fn prompt(&mut self, value: &str) -> &mut AuthSerializer

Set the prompt for open id.

§Example

oauth.prompt("login");
source

pub fn prompts(&mut self, value: &[Prompt]) -> &mut AuthSerializer

source

pub fn session_state(&mut self, value: &str) -> &mut AuthSerializer

Set the session state.

§Example
oauth.session_state("session-state");
source

pub fn grant_type(&mut self, value: &str) -> &mut AuthSerializer

Set the grant_type.

§Example
oauth.grant_type("token");
source

pub fn resource(&mut self, value: &str) -> &mut AuthSerializer

Set the resource.

§Example
oauth.resource("resource");
source

pub fn code_verifier(&mut self, value: &str) -> &mut AuthSerializer

Set the code verifier.

§Example
oauth.code_verifier("code_verifier");
source

pub fn domain_hint(&mut self, value: &str) -> &mut AuthSerializer

Set the domain hint.

§Example
oauth.domain_hint("domain_hint");
source

pub fn code_challenge(&mut self, value: &str) -> &mut AuthSerializer

Set the code challenge.

§Example
oauth.code_challenge("code_challenge");
source

pub fn code_challenge_method(&mut self, value: &str) -> &mut AuthSerializer

Set the code challenge method.

§Example
oauth.code_challenge_method("code_challenge_method");
source

pub fn login_hint(&mut self, value: &str) -> &mut AuthSerializer

Set the login hint.

§Example
oauth.login_hint("login_hint");
source

pub fn client_assertion(&mut self, value: &str) -> &mut AuthSerializer

Set the client assertion.

§Example
oauth.client_assertion("client_assertion");
source

pub fn client_assertion_type(&mut self, value: &str) -> &mut AuthSerializer

Set the client assertion type.

§Example
oauth.client_assertion_type("client_assertion_type");
source

pub fn username(&mut self, value: &str) -> &mut AuthSerializer

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

§Example
oauth.username("user");
assert!(oauth.contains(AuthParameter::Username))
source

pub fn password(&mut self, value: &str) -> &mut AuthSerializer

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

§Example
oauth.password("user");
assert!(oauth.contains(AuthParameter::Password))
source

pub fn refresh_token(&mut self, value: &str) -> &mut AuthSerializer

source

pub fn device_code(&mut self, value: &str) -> &mut AuthSerializer

Set the device code for the device authorization flow.

§Example
oauth.device_code("device_code");
assert!(oauth.contains(AuthParameter::DeviceCode))
source

pub fn add_scope<T: ToString>(&mut self, scope: T) -> &mut AuthSerializer

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");
source

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

Get the scopes.

§Example
let mut oauth = AuthSerializer::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"));
source

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

Join scopes.

§Example

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

pub fn set_scope<T: ToString, I: IntoIterator<Item = T>>( &mut self, iter: I ) -> &mut Self

Set scope. Overriding all previous scope values.

§Example

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

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

pub fn extend_scopes<T: ToString, I: IntoIterator<Item = T>>( &mut self, iter: I ) -> &mut Self

Extend scopes.

§Example

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

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

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

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"));
source§

impl AuthSerializer

source

pub fn encode_query( &mut self, optional_fields: Vec<AuthParameter>, required_fields: Vec<AuthParameter> ) -> IdentityResult<String>

source

pub fn as_credential_map( &mut self, optional_fields: Vec<AuthParameter>, required_fields: Vec<AuthParameter> ) -> IdentityResult<HashMap<String, String>>

Trait Implementations§

source§

impl Clone for AuthSerializer

source§

fn clone(&self) -> AuthSerializer

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for AuthSerializer

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for AuthSerializer

source§

fn default() -> AuthSerializer

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for AuthSerializer

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<V: ToString> Extend<(AuthParameter, V)> for AuthSerializer

Extend the OAuth credentials.

§Example

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

oauth.extend(map);
source§

fn extend<I: IntoIterator<Item = (AuthParameter, V)>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl PartialEq for AuthSerializer

source§

fn eq(&self, other: &AuthSerializer) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for AuthSerializer

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for AuthSerializer

source§

impl StructuralPartialEq for AuthSerializer

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

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

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

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

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

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