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: AsRef<str>, U: IntoUrl>( client_id: T, authorization_code: T, client_assertion: T, redirect_uri: Option<U>, ) -> IdentityResult<AuthorizationCodeCertificateCredential>
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) -> Self
fn from(credential: AuthorizationCodeCertificateCredential) -> Self
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) -> Self
fn from(value: AuthorizationCodeCertificateCredential) -> Self
Converts to this type from the input type.
Source§impl From<AuthorizationCodeCertificateCredentialBuilder> for AuthorizationCodeCertificateCredential
impl From<AuthorizationCodeCertificateCredentialBuilder> for AuthorizationCodeCertificateCredential
Source§fn from(builder: AuthorizationCodeCertificateCredentialBuilder) -> Self
fn from(builder: AuthorizationCodeCertificateCredentialBuilder) -> Self
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<Self::Token, AuthExecutionError>
fn get_token_silent_async<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Self::Token, AuthExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: '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) -> IdentityResult<HashMap<String, String>>
fn client_id(&self) -> &Uuid
fn azure_cloud_instance(&self) -> AzureCloudInstance
fn app_config(&self) -> &AppConfig
fn uri(&mut self) -> IdentityResult<Url>
fn request_parts(&mut self) -> IdentityResult<AuthorizationRequestParts>
fn build_request(&mut self) -> AuthExecutionResult<RequestBuilder>
fn build_request_async(&mut self) -> AuthExecutionResult<RequestBuilder>
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) -> AuthExecutionResult<Response>
fn execute_async<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = AuthExecutionResult<Response>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: '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