I’m querying the userinfo via the java authAPI with the following token
eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik5rSkNOa000TVRJeU5EY3hNamt4TWpjMlF6WTVSVUU1T0VVM01VWTJSa1V5TnpjMk5qUTRPUSJ9.eyJpc3MiOiJodHRwczovL21lbmluc3VpdHMuZXUuYXV0aDAuY29tLyIsInN1YiI6Im14ZjBNMTdnZnRKY0xLcXVkRlFUcE1yM093c0lOcEVzQGNsaWVudHMiLCJhdWQiOiJodHRwczovL2hhc2gubmV0YmxvZ2dlci5tZS8iLCJleHAiOjE1MDY0MjUwODUsImlhdCI6MTUwNjMzODY4NSwic2NvcGUiOiJwcm9maWxlIG9wZW5pZCByZWFkOmdyZWV0aW5nIn0.BWWDDkWf4TSKD_-FcO58V-Tvqjd84Tz7SFgvUOLFq8xiS6jcBuO4iiObcT6kmOw-q3eyv-pT09J0mRb13khGWjplX3IGijPC1n_SOV_J1uN7AaZzM4D0nfO2IzstFzw0t0fKdvEAvURadGjLy77bSlBLRuj1dD_ztIB6f4mqkyyuTTM-JWJLMLJyn3UFKtn8CsVEcSpyBdHVL1RzfvLfa_LysjPCQNsBJUP8JfIJ3G-A26i0PkUyy_zTCR4v74IElHTvP1PS2YbUc0RLyqTT9ptdXqv-szgI3xBXBDJLSG7dghaSuhYpdzvMTX_NmzMRZ-w8qibNy4Q7ABQ0bmT7PQ
[EDIT] This token was generated using the following:
curl --request POST \
--url https://meninsuits.eu.auth0.com/oauth/token \
--header 'content-type: application/json' \
--data '{"client_id":"xxx","client_secret":"xxx","audience":"https://hash.netblogger.me/","grant_type":"client_credentials"}'
This might not be the correct token to use, it seems this is only for server to server, think the correct way to do this is to actually generate the token on the front end and extract it and send it to the back end?
The Java code is as follows:
private AuthAPI auth = new AuthAPI("https://meninsuits.eu.auth0.com", "xx", "xx");
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@RequestMapping("/secure/greeting")
public Greeting secretGreeting(@RequestHeader("authorization") String authToken, @RequestParam(value="name", defaultValue="User") String name) {
String token = authToken.substring(authToken.indexOf(" ")+1);
Request<UserInfo> request = auth.userInfo(token);
try {
UserInfo info = request.execute();
} catch (APIException exception) {
System.out.println("API");
} catch (Auth0Exception exception) {
System.out.println("Auth");
}
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
The thing is even when calling /userinfo directly in postman I still get 401 so it seems its not related to the java code itself, The client is a test client (non-interactive) as I’m using spring as a backend API but I don’t see why this would make a difference. It seems like I’m missing something config wise but not really sure what, I’ve dug through all the docs and been directed to this page several times: http://community.auth0.com/questions/516/httpsuserinfo-returns-401-unauthorized