All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.scalecube.security.jwt.JwtAuthenticator Maven / Gradle / Ivy

There is a newer version: 1.0.33.rc1
Show newest version
package io.scalecube.security.jwt;

import io.jsonwebtoken.Claims;
import io.scalecube.security.api.Authenticator;
import io.scalecube.security.api.Profile;
import reactor.core.publisher.Mono;

public interface JwtAuthenticator extends Authenticator {

  /**
   * Authenticate a JWT token.
   *
   * @param token jwt token.
   * @return security profile.
   */
  Mono authenticate(String token);

  /**
   * Create a profile from claims.
   *
   * @param tokenClaims the claims to parse
   * @return a profile from the claims
   */
  default Profile profileFromClaims(Claims tokenClaims) {
    return Profile.builder()
        .userId(tokenClaims.get("sub", String.class))
        .tenant(tokenClaims.get("aud", String.class))
        .email(tokenClaims.get("email", String.class))
        .emailVerified(tokenClaims.get("email_verified", Boolean.class))
        .name(tokenClaims.get("name", String.class))
        .familyName(tokenClaims.get("family_name", String.class))
        .givenName(tokenClaims.get("given_name", String.class))
        .claims(tokenClaims)
        .build();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy