Auth0 Home Blog Docs

How do I get a User Email Address via Java code?



The below code feels close, but no objects with data that looks like anything that makes sense? Please help.

String domain = config.getServletContext().getInitParameter("com.auth0.domain");
    String clientId = config.getServletContext().getInitParameter("com.auth0.clientId");
    String clientSecret = config.getServletContext().getInitParameter("com.auth0.clientSecret");

  AuthAPI authAPI = new AuthAPI(domain, clientId, clientSecret);

  UserInfo userInfo = authAPI.userInfo((String)SessionUtils.get(request, "accessToken")).execute();



From this document:

“Creates a request to get the user information associated to a given access token. This will only work if the token has been granted the openid scope.”

Very helpful comment, if only a link to how to do this was included, or some example code existed. Not even test cases seem to exist, so odd.

            .withParameter("scope", "openid profile email")

I had to add code like this into the example LoginServlet.

Probably something that should just be delivered as part of that example application.