Validate Token Generate from an Application Native in Spring boot with Spring Security

Hi, i created a Application Native for React Native i did the integration and uses the universal login. Everything worked perfectly. I loged in and got the access token but i dont know how to validate it in Springboot. I read blog and all talk about Auth0 API and use the indentifier as audience but in Application Native there is not identifier and i dont know how to validate the token that i got from the Application Native from React.

The ide is to log in in my app get the token and then with that token validate the petitions in my spring boot API.

Hi @carlosarce16, welcome to the community!

You would need to set up an API on your Auth0 tenant to represent your Springboot APIs, please see here: https://auth0.com/docs/getting-started/set-up-api

The identifier you set for this API is the audience you should use when you request an access token. You can specify this audience in the authorize call: https://auth0.github.io/react-native-auth0/WebAuth.html#.authorize

You may find this solution overview of help: https://auth0.com/docs/architecture-scenarios/mobile-api/part-1

As for validating this token on the API side, there are some steps here: https://auth0.com/docs/tokens/guides/validate-access-tokens#custom-api-access-tokens

In the blog post you mentioned (I believe you were referring to this? - https://auth0.com/blog/implementing-jwt-authentication-on-spring-boot/) you can see how they used the java-jwt library to validate the token -
https://github.com/auth0/java-jwt/blob/master/lib/src/main/java/com/auth0/jwt/JWT.java

But there are many 3rd party JWT libraries out there, you can find more information on them here: https://jwt.io/
Or you could manually implement the checks: https://auth0.com/docs/tokens/guides/validate-jwts#manually-implement-the-checks

Hi, thank you for your answer.

what i understand is that in my ReactNative app i have to put the audience with the identifier of my Auth0 API.

This is my native app

This is my API

On my react native app everything was working fine. I use the universal login i got the access toke.

Like this.
image

In order to set the audience to linked to my Auth0 API i did this.


I getting “access_denied: Service not found: https://cafetoevent/userinfo

But if a change audience for “https://clarce.auth0.com/userinfo” everything wokrs fine again.

My question is: how do i link the token generated on my React Native app from Auth0 Native to my Auth0 API that is the one that i implement in springboot? Because in Springboot i need and audience that for the Auth0 API is the identifier “https://cafetoevent/”.

You will need to match the audience with the API identifier you configured exactly.
So if you used “https://cafetoevent/” as the audience in the authorize call instead, you should not get the error, and would then receive an access token intended for your “CafetoEventAPI”.
Your Springboot API would then need to validate this token when the user sent a request to your API, one of these checks would be making sure the “aud” (audience) parameter in the token matches “https://cafetoevent/”, in your case.

1 Like

Hi @sgo :grinning: thaks for answering.
but how do i match the audience on mi React Native application to my Auth0 API identifier? when i change it to match “https://cafetoevent/” or “https://cafetoevent/userinfo” i got “service not found” and only works with “https://clarce.auth0.com/userinfo” tha is the domain of my account and i can loginand then i get the token.

I been searching arround the documentation but i can’t find how make it work.

Hi @carlosarce16, could you please share a code snippet of what you tried when you set the audience to “https://cafetoevent/” on your React Native app and got the service not found error?