[JWT Autenticator] Retrieve user data from token payload


I’m working on SPA (angular 5), Is there a way to retrieve the user data directly from the token payload ?

Best regards


could you please be a bit more detailed? What do you try to achieve? What have you tried? What doesn’t work?

Best regards,


I want to get the user data directly from a custom JWT claim, instead of calling a web service that returns a user based on token (like what you have done on the angularjs seed).

The decode of the current token returns the json below:

{ "sub": "1-Ql+rqG4uuzhyAl9jlvA5Jj4k+BCGcq1RmebRUOrtdlU3fr/4Wenyck25py3+vhXRezodGjTA8lokehbGQagFhMITFK9HpZ50QhqRbg==", "iss": "play-silhouette", "exp": 1516800039, "iat": 1514208039, "jti": "ec68f15b3a03cc0b7a9100adcf68e24b1108abb2d12e2e6c9578d2ee4ed5a9ce1e7808abdd4e401aa053814c16f39cc864eb6d4d1e2f65d5e3d85fd10c6bce53068768ad266a21f7447cff517133fd7962b2beea1f2622d69ead98fbccb679833ed5d1898f6b4d9b6cb73d2e3640e622adf1f85aeff6e82c2cc7ecde7409cca0" }

is there a way to add a user claim to my JWT ?

After you have created the authenticator you can add custom payload to the authenticator. This payload will be added to the JWT.

Can you please give more details ?

The JWTAuthenticator has a customClaims property. So after you have created a JWTAuthenticator with the JWTAuthenticatorService.create method, you can add a JSON object to the authenticators customClaims property. The JWTAuthenticator is a case class, so it has a copy method which you can use to create a copy of the authenticator which contains your custom claims.

1 Like

You can use it like this.

authenticator => authenticator.copy(customClaims = Option(JsObject(Seq(
                    "name" -> JsString("Watership Down")
1 Like