mapPrincipal

inline fun <P : Any, R : Any, C> AuthenticationScheme<P, C>.mapPrincipal(noinline transform: suspend RoutingContext.(P) -> R?): AuthenticationScheme<R, C>(source)

Returns a scheme that produces R by transforming every successfully resolved principal of type P.

The returned scheme reuses this scheme's provider and extension. If the original resolver returns null, the transformation is not invoked and authentication fails as before. If transform returns null, the scheme registers an AuthenticationFailedCause.InvalidCredentials challenge and rejects both required and optional authentication. Route-level and scheme-level onUnauthorized handlers receive that cause. When neither handler nor a provider challenge responds, authentication fails with 401 Unauthorized. Exceptions thrown by transform propagate.

Report a problem

Return

a scheme that produces R and reuses this scheme's provider and extension.

Parameters

transform

maps a successfully resolved principal to R, or null to reject the credentials.

Type Parameters

P

the principal type produced by this scheme.

R

the principal type produced by transform.

C

the intrinsic extension context preserved on the returned scheme.