pub struct IamClient { /* private fields */ }Expand description
Client forPharia Identity Access Management. Authenticate and authorize users.
Implementations§
Source§impl IamClient
impl IamClient
Sourcepub fn new(base_url: String) -> Self
pub fn new(base_url: String) -> Self
Construct a new client using the respective IAM instance. E.g. IAM_PRODUCTION_URL
Sourcepub async fn check_user<'a>(
&self,
token: impl Display,
permissions: &'a [Permission<'a>],
) -> Result<UserInfoAndPermissions, CheckUserError>
pub async fn check_user<'a>( &self, token: impl Display, permissions: &'a [Permission<'a>], ) -> Result<UserInfoAndPermissions, CheckUserError>
One stop shop for both authentication and authorization.
§Parameters
token: Service or user token used for authentication.permissions: A list of all permissions you are interested in. The response will contain the subset of these permissions which are privileges the user has.
Example Authorize Assistant Access against production instance
pub use pharia_common::{IamClient, Permission, IAM_PRODUCTION_URL, CheckUserError};
pub async fn is_authorized(token: &str) -> Result<bool, CheckUserError> {
let iam = IamClient::new(IAM_PRODUCTION_URL.to_owned());
let permissions = [Permission::AccessAssistant];
let user_info = iam.check_user(token, &permissions).await?;
let is_authorized = user_info.permissions == permissions;
Ok(is_authorized)
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for IamClient
impl !RefUnwindSafe for IamClient
impl Send for IamClient
impl Sync for IamClient
impl Unpin for IamClient
impl !UnwindSafe for IamClient
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