pub struct MicrosoftAuth { /* private fields */ }Expand description
Microsoft authenticator using Device Code Flow
This authentication method is suitable for CLI applications and launchers. The user will need to visit a URL and enter a code to authorize.
§Example
use lighty_auth::microsoft::MicrosoftAuth;
use lighty_auth::Authenticator;
#[tokio::main]
async fn main() {
let mut auth = MicrosoftAuth::new("your-client-id");
// Set a callback to display the device code to the user
auth.set_device_code_callback(|code, url| {
println!("Please visit: {}", url);
println!("And enter code: {}", code);
});
let profile = auth.authenticate().await.unwrap();
println!("Logged in as: {}", profile.username);
}Implementations§
Source§impl MicrosoftAuth
impl MicrosoftAuth
Sourcepub fn set_device_code_callback<F>(&mut self, callback: F)
pub fn set_device_code_callback<F>(&mut self, callback: F)
Set a callback to display the device code to the user
§Arguments
callback: Function that receives (code, verification_url)
Sourcepub fn set_poll_interval(&mut self, interval: Duration)
pub fn set_poll_interval(&mut self, interval: Duration)
Set the polling interval
Default: 5 seconds
Sourcepub fn set_timeout(&mut self, timeout: Duration)
pub fn set_timeout(&mut self, timeout: Duration)
Set the authentication timeout
Default: 5 minutes
Trait Implementations§
Source§impl Authenticator for MicrosoftAuth
impl Authenticator for MicrosoftAuth
Source§async fn authenticate(&mut self) -> AuthResult<UserProfile>
async fn authenticate(&mut self) -> AuthResult<UserProfile>
Authenticate a user and return their profile Read more
Source§fn verify(
&self,
token: &str,
) -> impl Future<Output = AuthResult<UserProfile>> + Send
fn verify( &self, token: &str, ) -> impl Future<Output = AuthResult<UserProfile>> + Send
Verify if a token is still valid Read more
Auto Trait Implementations§
impl Freeze for MicrosoftAuth
impl !RefUnwindSafe for MicrosoftAuth
impl Send for MicrosoftAuth
impl Sync for MicrosoftAuth
impl Unpin for MicrosoftAuth
impl !UnwindSafe for MicrosoftAuth
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more