# Isue with auth0-java calling the userinfo endpoint

**URL:** <https://community.auth0.com/t/isue-with-auth0-java-calling-the-userinfo-endpoint/7036>\
**Category:** Get Help\
**Tags:** auth0-java\
**Created:** [June 13, 2017, 2:07pm UTC](https://community.auth0.com/t/isue-with-auth0-java-calling-the-userinfo-endpoint/7036 "2017-06-13T14:07:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![a.ubels](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/a.ubels/32/4122_2.png) [@a.ubels](https://community.auth0.com/u/a.ubels)\
**Post date:** [June 13, 2017, 2:07pm UTC](https://community.auth0.com/t/isue-with-auth0-java-calling-the-userinfo-endpoint/7036/1 "2017-06-13T14:07:21Z")

</div>

I had some previous code, however after updating to the latest Auth0 java client, I can no longer:

1. Do a server sided password login;
2. Use that to retrieve the `user_metadata`

The current code I am using is (in a test btw)

```
    AuthAPI auth0 = new AuthAPI(domain, clientId, clientSecret);

    TokenHolder tokenHolder = auth0.login(user, pass)
            .setAudience(audience)
            .execute();

    String token = tokenHolder.getAccessToken();
    UserInfo profile = auth0.userInfo(token).execute();

    System.out.println(profile.getValues().get("email"));
    System.out.println(profile.getValues().get("user_metadata"));

```

And the error I get at line:

```
    UserInfo profile = auth0.userInfo(token).execute();

```

Is:

```
   com.auth0.exception.APIException: Request failed with status code 401: invalid credentials
at com.auth0.net.CustomRequest.createResponseException(CustomRequest.java:104)
at com.auth0.net.CustomRequest.parseResponse(CustomRequest.java:57)
at com.auth0.net.BaseRequest.execute(BaseRequest.java:37)
at example.Auth0Tests.TestToken(Auth0Tests.java:89)

```

I can’t figure out what I need to change to get this to work.. What am I doing wrong? Previously I had no issues.

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [June 13, 2017, 3:36pm UTC](https://community.auth0.com/t/isue-with-auth0-java-calling-the-userinfo-endpoint/7036/2 "2017-06-13T15:36:23Z")

</div>

Based on the information available the likely cause is that the access token being issued is not valid to call the `/userinfo` endpoint. In particular, this may be due to that fact that **you’re not specifying a `scope` parameter containing the `openid` value** so that the request is handled in accordance to OpenID Connect.

In addition, the API associated with the audience you’re providing needs to be using RS256 as the signing algorithm. You can read more about the possible causes for the behavior you’re seeing at:

[http://community.auth0.com/questions/516/httpsuserinfo-returns-401-unauthorized](http://community.auth0.com/questions/516/httpsuserinfo-returns-401-unauthorized)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 2, 2018, 5:54am UTC](https://community.auth0.com/t/isue-with-auth0-java-calling-the-userinfo-endpoint/7036/3 "2018-03-02T05:54:35Z")

</div>


