pub struct IamClient { /* private fields */ }Expand description
Client forPharia Identity Access Management. Authenticate and authorize users.
Implementations§
Source§impl IamClient
impl IamClient
Sourcepub fn builder(base_url: String) -> IamClientBuilder
pub fn builder(base_url: String) -> IamClientBuilder
Use this instead of IamClient::new if you want to have additional middleware.
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 asking a set of permissions. While this method
returns a subset of permissions to which matches the privileges of the user it does not
perform the authorization check. Call authorize
§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.
Same as check_user but also performs the authorization check and fails if the user is not
authorized.
§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: Check if the user has the AccessAssistant permission.
use pharia_common::{Permission, IamClient, AuthorizationError, IAM_PRODUCTION_URL};
pub async fn authorize(token: &str) -> Result<(), AuthorizationError> {
let iam = IamClient::new(IAM_PRODUCTION_URL.to_owned());
let permissions = [Permission::AccessAssistant];
let user_info = iam.authorize(token, &permissions).await?;
Ok(())
}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 UnsafeUnpin 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