pub struct AuthCodeAuthorizationUrlParameters { /* private fields */ }
Expand description
Get the authorization url required to perform the initial authorization and redirect in the authorization code flow.
The authorization code flow begins with the client directing the user to the /authorize endpoint.
The OAuth 2.0 authorization code grant type, or auth code flow, enables a client application to obtain authorized access to protected resources like web APIs. The auth code flow requires a user-agent that supports redirection from the authorization server (the Microsoft identity platform) back to your application. For example, a web browser, desktop, or mobile application operated by a user to sign in to your app and access their data.
Reference: https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow#request-an-authorization-code
§Build a confidential client for the authorization code grant.
Use with_authorization_code to set the authorization code received from the authorization step, see Request an authorization code You can use the AuthCodeAuthorizationUrlParameterBuilder to build the url that the user will be directed to authorize at.
use uuid::Uuid;
use graph_oauth::{AzureCloudInstance, ConfidentialClientApplication, Prompt};
use url::Url;
let auth_url_builder = ConfidentialClientApplication::builder(Uuid::new_v4())
.auth_code_url_builder()
.with_tenant("tenant-id")
.with_prompt(Prompt::Login)
.with_state("1234")
.with_scope(vec!["User.Read"])
.with_redirect_uri(Url::parse("http://localhost:8000").unwrap())
.build();
let url = auth_url_builder.url();
// or
let url = auth_url_builder.url_with_host(&AzureCloudInstance::AzurePublic);
Implementations§
source§impl AuthCodeAuthorizationUrlParameters
impl AuthCodeAuthorizationUrlParameters
pub fn new( client_id: impl AsRef<str>, redirect_uri: impl IntoUrl ) -> IdentityResult<AuthCodeAuthorizationUrlParameters>
pub fn builder( client_id: impl TryInto<Uuid> ) -> AuthCodeAuthorizationUrlParameterBuilder
pub fn url(&self) -> IdentityResult<Url>
pub fn url_with_host( &self, azure_cloud_instance: &AzureCloudInstance ) -> IdentityResult<Url>
pub fn into_credential( self, authorization_code: impl AsRef<str> ) -> AuthorizationCodeCredentialBuilder
pub fn into_assertion_credential( self, authorization_code: impl AsRef<str> ) -> AuthorizationCodeAssertionCredentialBuilder
sourcepub fn nonce(&mut self) -> Option<&String>
pub fn nonce(&mut self) -> Option<&String>
Get the nonce.
This value may be generated automatically by the client and may be useful for users who want to manually verify that the nonce stored in the client is the same as the nonce returned in the response from the authorization server. Verifying the nonce helps mitigate token replay attacks.
Trait Implementations§
source§impl AuthorizationUrl for AuthCodeAuthorizationUrlParameters
impl AuthorizationUrl for AuthCodeAuthorizationUrlParameters
fn redirect_uri(&self) -> Option<&Url>
source§impl Clone for AuthCodeAuthorizationUrlParameters
impl Clone for AuthCodeAuthorizationUrlParameters
source§fn clone(&self) -> AuthCodeAuthorizationUrlParameters
fn clone(&self) -> AuthCodeAuthorizationUrlParameters
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more