pub struct AuthManager { /* private fields */ }
Expand description
Authentication manager for handling login, logout, and token management
Implementations§
Source§impl AuthManager
impl AuthManager
Sourcepub async fn login<S1, S2>(
&self,
email: S1,
password: S2,
) -> Result<AuthResponse>
pub async fn login<S1, S2>( &self, email: S1, password: S2, ) -> Result<AuthResponse>
Login with email and password
§Arguments
email
- User email addresspassword
- User password
§Examples
use zero_trust_sdk::{ZeroTrustClient, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new("https://api.zerotrust.com")?;
let client = ZeroTrustClient::new(config).await?;
let auth_response = client.auth()
.login("user@example.com", "password")
.await?;
println!("Logged in as: {}", auth_response.user.email);
Ok(())
}
Sourcepub async fn register<S1, S2, S3>(
&self,
email: S1,
password: S2,
role: Option<S3>,
) -> Result<AuthResponse>
pub async fn register<S1, S2, S3>( &self, email: S1, password: S2, role: Option<S3>, ) -> Result<AuthResponse>
Register a new user account
§Arguments
email
- User email addresspassword
- User passwordrole
- Optional user role (defaults to “user”)
§Examples
use zero_trust_sdk::{ZeroTrustClient, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new("https://api.zerotrust.com")?;
let client = ZeroTrustClient::new(config).await?;
let auth_response = client.auth()
.register("newuser@example.com", "securepassword", Some("admin"))
.await?;
println!("Registered user: {}", auth_response.user.email);
Ok(())
}
Sourcepub async fn logout(&self) -> Result<()>
pub async fn logout(&self) -> Result<()>
Logout the current user
§Examples
use zero_trust_sdk::{ZeroTrustClient, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new("https://api.zerotrust.com")?
.with_token("your-jwt-token");
let client = ZeroTrustClient::new(config).await?;
client.auth().logout().await?;
println!("Logged out successfully");
Ok(())
}
Sourcepub async fn me(&self) -> Result<User>
pub async fn me(&self) -> Result<User>
Get current user information
§Examples
use zero_trust_sdk::{ZeroTrustClient, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new("https://api.zerotrust.com")?
.with_token("your-jwt-token");
let client = ZeroTrustClient::new(config).await?;
let user = client.auth().me().await?;
println!("Current user: {} ({})", user.email, user.role);
Ok(())
}
Sourcepub async fn refresh_token(&self) -> Result<String>
pub async fn refresh_token(&self) -> Result<String>
Refresh the authentication token
§Examples
use zero_trust_sdk::{ZeroTrustClient, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new("https://api.zerotrust.com")?
.with_token("your-jwt-token");
let client = ZeroTrustClient::new(config).await?;
let new_token = client.auth().refresh_token().await?;
println!("Token refreshed: {}", new_token);
Ok(())
}
Sourcepub async fn change_password<S1, S2>(
&self,
current_password: S1,
new_password: S2,
) -> Result<()>
pub async fn change_password<S1, S2>( &self, current_password: S1, new_password: S2, ) -> Result<()>
Change user password
§Arguments
current_password
- Current passwordnew_password
- New password
§Examples
use zero_trust_sdk::{ZeroTrustClient, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new("https://api.zerotrust.com")?
.with_token("your-jwt-token");
let client = ZeroTrustClient::new(config).await?;
client.auth()
.change_password("oldpassword", "newpassword")
.await?;
println!("Password changed successfully");
Ok(())
}
Trait Implementations§
Source§impl Clone for AuthManager
impl Clone for AuthManager
Source§fn clone(&self) -> AuthManager
fn clone(&self) -> AuthManager
Returns a duplicate 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 moreAuto Trait Implementations§
impl Freeze for AuthManager
impl !RefUnwindSafe for AuthManager
impl Send for AuthManager
impl Sync for AuthManager
impl Unpin for AuthManager
impl !UnwindSafe for AuthManager
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more