pub struct AuthorizationCodeCertificateCredential { /* private fields */ }
Expand description
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. https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow’
[X509Certificate] requires features = [“openssl”]
ⓘ
use graph_rs_sdk::oauth::{
ClientCertificateCredential, ConfidentialClientApplication, PKey, X509Certificate, X509,
};
use std::fs::File;
use std::io::Read;
use std::path::Path;
pub fn x509_certificate(
client_id: &str,
tenant: &str,
public_key_path: impl AsRef<Path>,
private_key_path: impl AsRef<Path>,
) -> anyhow::Result<X509Certificate> {
// Use include_bytes!(file_path) if the files are local
let mut cert_file = File::open(public_key_path)?;
let mut certificate: Vec<u8> = Vec::new();
cert_file.read_to_end(&mut certificate)?;
let mut private_key_file = File::open(private_key_path)?;
let mut private_key: Vec<u8> = Vec::new();
private_key_file.read_to_end(&mut private_key)?;
let cert = X509::from_pem(certificate.as_slice())?;
let pkey = PKey::private_key_from_pem(private_key.as_slice())?;
Ok(X509Certificate::new_with_tenant(
client_id, tenant, cert, pkey,
))
}
fn build_confidential_client(
client_id: &str,
tenant: &str,
scope: Vec<&str>,
x509certificate: X509Certificate,
) -> anyhow::Result<ConfidentialClientApplication<ClientCertificateCredential>> {
Ok(ConfidentialClientApplication::builder(client_id)
.with_client_x509_certificate(&x509certificate)?
.with_tenant(tenant)
.with_scope(scope)
.build())
}
Implementations§
Source§impl AuthorizationCodeCertificateCredential
impl AuthorizationCodeCertificateCredential
pub fn new<T, U>( client_id: T, authorization_code: T, client_assertion: T, redirect_uri: Option<U>, ) -> Result<AuthorizationCodeCertificateCredential, AuthorizationFailure>
Trait Implementations§
Source§impl Clone for AuthorizationCodeCertificateCredential
impl Clone for AuthorizationCodeCertificateCredential
Source§fn clone(&self) -> AuthorizationCodeCertificateCredential
fn clone(&self) -> AuthorizationCodeCertificateCredential
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl From<AuthorizationCodeCertificateCredential> for AuthorizationCodeCertificateCredentialBuilder
impl From<AuthorizationCodeCertificateCredential> for AuthorizationCodeCertificateCredentialBuilder
Source§fn from(
credential: AuthorizationCodeCertificateCredential,
) -> AuthorizationCodeCertificateCredentialBuilder
fn from( credential: AuthorizationCodeCertificateCredential, ) -> AuthorizationCodeCertificateCredentialBuilder
Converts to this type from the input type.
Source§impl From<AuthorizationCodeCertificateCredential> for ConfidentialClientApplication<AuthorizationCodeCertificateCredential>
impl From<AuthorizationCodeCertificateCredential> for ConfidentialClientApplication<AuthorizationCodeCertificateCredential>
Source§fn from(
value: AuthorizationCodeCertificateCredential,
) -> ConfidentialClientApplication<AuthorizationCodeCertificateCredential>
fn from( value: AuthorizationCodeCertificateCredential, ) -> ConfidentialClientApplication<AuthorizationCodeCertificateCredential>
Converts to this type from the input type.
Source§impl From<AuthorizationCodeCertificateCredentialBuilder> for AuthorizationCodeCertificateCredential
impl From<AuthorizationCodeCertificateCredentialBuilder> for AuthorizationCodeCertificateCredential
Source§fn from(
builder: AuthorizationCodeCertificateCredentialBuilder,
) -> AuthorizationCodeCertificateCredential
fn from( builder: AuthorizationCodeCertificateCredentialBuilder, ) -> AuthorizationCodeCertificateCredential
Converts to this type from the input type.
Source§impl TokenCache for AuthorizationCodeCertificateCredential
impl TokenCache for AuthorizationCodeCertificateCredential
type Token = Token
fn get_token_silent( &mut self, ) -> Result<<AuthorizationCodeCertificateCredential as TokenCache>::Token, AuthExecutionError>
fn get_token_silent_async<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<<AuthorizationCodeCertificateCredential as TokenCache>::Token, AuthExecutionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
AuthorizationCodeCertificateCredential: 'async_trait,
fn with_force_token_refresh(&mut self, force_token_refresh: ForceTokenRefresh)
Source§impl TokenCredentialExecutor for AuthorizationCodeCertificateCredential
impl TokenCredentialExecutor for AuthorizationCodeCertificateCredential
fn form_urlencode( &mut self, ) -> Result<HashMap<String, String>, AuthorizationFailure>
fn client_id(&self) -> &Uuid
fn azure_cloud_instance(&self) -> AzureCloudInstance
fn app_config(&self) -> &AppConfig
fn uri(&mut self) -> Result<Url, AuthorizationFailure>
fn request_parts( &mut self, ) -> Result<AuthorizationRequestParts, AuthorizationFailure>
fn build_request(&mut self) -> Result<RequestBuilder, AuthExecutionError>
fn build_request_async(&mut self) -> Result<RequestBuilder, AuthExecutionError>
fn basic_auth(&self) -> Option<(String, String)>
fn extra_header_parameters(&self) -> &HeaderMap
fn issuer(&self) -> Result<Url, ParseError>
fn extra_query_parameters(&self) -> &HashMap<String, String>
fn execute(&mut self) -> Result<Response, AuthExecutionError>
fn execute_async<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Response, AuthExecutionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: Send + 'async_trait,
Auto Trait Implementations§
impl Freeze for AuthorizationCodeCertificateCredential
impl !RefUnwindSafe for AuthorizationCodeCertificateCredential
impl Send for AuthorizationCodeCertificateCredential
impl Sync for AuthorizationCodeCertificateCredential
impl Unpin for AuthorizationCodeCertificateCredential
impl !UnwindSafe for AuthorizationCodeCertificateCredential
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
Mutably borrows from an owned value. Read more