Struct mailpot_web::auth::auth_request::RequireAuthorizationLayer
source · pub struct RequireAuthorizationLayer<UserId, User, Role = ()>(UserId, User, Role);
Expand description
A wrapper around [tower_http::auth::RequireAuthorizationLayer
] which
provides login authorization.
Tuple Fields§
§0: UserId
§1: User
§2: Role
Implementations§
source§impl<UserId, User, Role> RequireAuthorizationLayer<UserId, User, Role>where
Role: PartialOrd + PartialEq + Clone + Send + Sync + 'static,
User: AuthUser<UserId, Role>,
impl<UserId, User, Role> RequireAuthorizationLayer<UserId, User, Role>where Role: PartialOrd + PartialEq + Clone + Send + Sync + 'static, User: AuthUser<UserId, Role>,
sourcepub fn login<ResBody>(
) -> RequireAuthorizationLayer<Login<UserId, User, ResBody, Role>>where
ResBody: HttpBody + Default,
pub fn login<ResBody>( ) -> RequireAuthorizationLayer<Login<UserId, User, ResBody, Role>>where ResBody: HttpBody + Default,
Authorizes requests by requiring a logged in user, otherwise it
rejects with http::StatusCode::UNAUTHORIZED
.
sourcepub fn login_with_role<ResBody>(
role_bounds: impl RangeBounds<Role> + Clone + Send + Sync + 'static
) -> RequireAuthorizationLayer<Login<UserId, User, ResBody, Role>>where
ResBody: HttpBody + Default,
pub fn login_with_role<ResBody>( role_bounds: impl RangeBounds<Role> + Clone + Send + Sync + 'static ) -> RequireAuthorizationLayer<Login<UserId, User, ResBody, Role>>where ResBody: HttpBody + Default,
Authorizes requests by requiring a logged in user to have a specific
range of roles, otherwise it rejects with
http::StatusCode::UNAUTHORIZED
.
sourcepub fn login_or_redirect<ResBody>(
login_url: Arc<Cow<'static, str>>,
redirect_field_name: Option<Arc<Cow<'static, str>>>
) -> RequireAuthorizationLayer<Login<UserId, User, ResBody, Role>>where
ResBody: HttpBody + Default,
pub fn login_or_redirect<ResBody>( login_url: Arc<Cow<'static, str>>, redirect_field_name: Option<Arc<Cow<'static, str>>> ) -> RequireAuthorizationLayer<Login<UserId, User, ResBody, Role>>where ResBody: HttpBody + Default,
Authorizes requests by requiring a logged in user, otherwise it redirects to the provided login URL.
If redirect_field_name
is set to a value, the login page will
receive the path it was redirected from in the URI query
part. For example, attempting to visit a protected path
/protected
would redirect you to /login?next=/protected
allowing
you to know how to return the visitor to their requested
page.
sourcepub fn login_with_role_or_redirect<ResBody>(
role_bounds: impl RangeBounds<Role> + Clone + Send + Sync + 'static,
login_url: Arc<Cow<'static, str>>,
redirect_field_name: Option<Arc<Cow<'static, str>>>
) -> RequireAuthorizationLayer<Login<UserId, User, ResBody, Role>>where
ResBody: HttpBody + Default,
pub fn login_with_role_or_redirect<ResBody>( role_bounds: impl RangeBounds<Role> + Clone + Send + Sync + 'static, login_url: Arc<Cow<'static, str>>, redirect_field_name: Option<Arc<Cow<'static, str>>> ) -> RequireAuthorizationLayer<Login<UserId, User, ResBody, Role>>where ResBody: HttpBody + Default,
Authorizes requests by requiring a logged in user to have a specific range of roles, otherwise it redirects to the provided login URL.
If redirect_field_name
is set to a value, the login page will
receive the path it was redirected from in the URI query
part. For example, attempting to visit a protected path
/protected
would redirect you to /login?next=/protected
allowing
you to know how to return the visitor to their requested
page.