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
impl AuthSerializer
sourcepub fn new() -> AuthSerializer
pub fn new() -> AuthSerializer
Create a new OAuth instance.
§Example
use graph_oauth::extensions::AuthSerializer;
let mut oauth = AuthSerializer::new();
sourcepub fn insert<V: ToString>(
&mut self,
oac: AuthParameter,
value: V
) -> &mut AuthSerializer
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));
sourcepub fn entry_with<V: ToString>(
&mut self,
oac: AuthParameter,
value: V
) -> &mut String
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")
sourcepub fn get(&self, oac: AuthParameter) -> Option<String>
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());
sourcepub fn contains(&self, t: AuthParameter) -> bool
pub fn contains(&self, t: AuthParameter) -> bool
Check if an OAuth credential has already been set.
§Example
println!("{:#?}", oauth.contains(AuthParameter::Nonce));
pub fn contains_key(&self, key: &str) -> bool
sourcepub fn remove(&mut self, oac: AuthParameter) -> &mut AuthSerializer
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);
sourcepub fn client_id(&mut self, value: &str) -> &mut AuthSerializer
pub fn client_id(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn state(&mut self, value: &str) -> &mut AuthSerializer
pub fn state(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn client_secret(&mut self, value: &str) -> &mut AuthSerializer
pub fn client_secret(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn redirect_uri(&mut self, value: &str) -> &mut AuthSerializer
pub fn redirect_uri(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn response_mode(&mut self, value: &str) -> &mut AuthSerializer
pub fn response_mode(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn response_type<T: ToString>(&mut self, value: T) -> &mut AuthSerializer
pub fn response_type<T: ToString>(&mut self, value: T) -> &mut AuthSerializer
pub fn response_types( &mut self, value: Iter<'_, ResponseType> ) -> &mut AuthSerializer
sourcepub fn nonce(&mut self, value: &str) -> &mut AuthSerializer
pub fn nonce(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn prompt(&mut self, value: &str) -> &mut AuthSerializer
pub fn prompt(&mut self, value: &str) -> &mut AuthSerializer
pub fn prompts(&mut self, value: &[Prompt]) -> &mut AuthSerializer
sourcepub fn session_state(&mut self, value: &str) -> &mut AuthSerializer
pub fn session_state(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn grant_type(&mut self, value: &str) -> &mut AuthSerializer
pub fn grant_type(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn resource(&mut self, value: &str) -> &mut AuthSerializer
pub fn resource(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn code_verifier(&mut self, value: &str) -> &mut AuthSerializer
pub fn code_verifier(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn domain_hint(&mut self, value: &str) -> &mut AuthSerializer
pub fn domain_hint(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn code_challenge(&mut self, value: &str) -> &mut AuthSerializer
pub fn code_challenge(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn code_challenge_method(&mut self, value: &str) -> &mut AuthSerializer
pub fn code_challenge_method(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn login_hint(&mut self, value: &str) -> &mut AuthSerializer
pub fn login_hint(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn client_assertion(&mut self, value: &str) -> &mut AuthSerializer
pub fn client_assertion(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn client_assertion_type(&mut self, value: &str) -> &mut AuthSerializer
pub fn client_assertion_type(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn username(&mut self, value: &str) -> &mut AuthSerializer
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))
sourcepub fn password(&mut self, value: &str) -> &mut AuthSerializer
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))
pub fn refresh_token(&mut self, value: &str) -> &mut AuthSerializer
sourcepub fn device_code(&mut self, value: &str) -> &mut AuthSerializer
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))
sourcepub fn add_scope<T: ToString>(&mut self, scope: T) -> &mut AuthSerializer
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");
sourcepub fn get_scopes(&self) -> &BTreeSet<String>
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"));
sourcepub fn join_scopes(&self, sep: &str) -> String
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);
sourcepub fn set_scope<T: ToString, I: IntoIterator<Item = T>>(
&mut self,
iter: I
) -> &mut Self
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");
sourcepub fn extend_scopes<T: ToString, I: IntoIterator<Item = T>>(
&mut self,
iter: I
) -> &mut Self
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");
sourcepub fn contains_scope<T: ToString>(&self, scope: T) -> bool
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
impl AuthSerializer
pub fn encode_query( &mut self, optional_fields: Vec<AuthParameter>, required_fields: Vec<AuthParameter> ) -> IdentityResult<String>
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
impl Clone for AuthSerializer
source§fn clone(&self) -> AuthSerializer
fn clone(&self) -> AuthSerializer
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for AuthSerializer
impl Debug for AuthSerializer
source§impl Default for AuthSerializer
impl Default for AuthSerializer
source§fn default() -> AuthSerializer
fn default() -> AuthSerializer
source§impl<'de> Deserialize<'de> for AuthSerializer
impl<'de> Deserialize<'de> for AuthSerializer
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<V: ToString> Extend<(AuthParameter, V)> for AuthSerializer
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)
fn extend<I: IntoIterator<Item = (AuthParameter, V)>>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl PartialEq for AuthSerializer
impl PartialEq for AuthSerializer
source§fn eq(&self, other: &AuthSerializer) -> bool
fn eq(&self, other: &AuthSerializer) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for AuthSerializer
impl Serialize for AuthSerializer
impl Eq for AuthSerializer
impl StructuralPartialEq for AuthSerializer
Auto Trait Implementations§
impl Freeze for AuthSerializer
impl RefUnwindSafe for AuthSerializer
impl Send for AuthSerializer
impl Sync for AuthSerializer
impl Unpin for AuthSerializer
impl UnwindSafe for AuthSerializer
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.