Auth0 Home Blog Docs

Use Java to get email from the Callback

auth0
email

#1

I have the following code to create my Auth0 Request…

public String getAuthUrl(HttpServletRequest req){
    return this.controller.buildAuthorizeUrl(
            req, getRedirectUrl(req)
    ).withAudience(
            String.format(
                    "https://%s/userinfo",
                    appConfig.getDomain()
            )
    ).withScope("openid email profile").build();
}

But I cannot figure out how to get the email out of the session in

public void handleCallback(HttpServletRequest req, HttpServletResponse res)

How do I extract out the email without calling back to auth0?


#2

Seems like I can get it like

 ((PayloadImpl)((JWTDecoder)tokenAuth.jwt).payload).tree.get("email")

But that seems really hacky.