Using Profile Information

After you have signed in the user with a now.gg account, you now have the id_token. To get user details that you received in OnTokenAcquired, you have to call the verifyToken function.
If your app has a backend server and you wish to fetch the User Profile for a signed-in user at your backend, please refer to this section.

Warning

  • Do not use a user’s email address or user ID to communicate the currently signed-in user to your app’s backend server. Instead, send the user’s ID token to your backend server and validate the token on the server.

If your app does not have a backend server, you can use the following section to retrieve user profile information.

Retrieve profile information

You can get the profile information for a logged-in user, using an on-device API call. To do this, use the userDataVerified field from the TokenVerifyResponse that you received by calling the verifyToken function.

UserDataVerified userData = tokenVerifyResponse.getUserDataVerified();
 String userId = userData.getUserId();
 String name = userData.getName();
 String email = userData.getEmail();
 String picture = userData.getPicture();
 
 public class UserDataVerified {
   String iss;
   String sub;
   String aud;
   String exp;
   String iat;
   String auth_time;
   String tokenId;
   String sessionId;
   String scope;

   String email;
   String name;
   String picture;
   String mobile;
   String userId;

   public UserDataVerified(String iss, String sub, String aud, String exp, String iat,
                           String auth_time, String email, String mobile, String userId,
                           String tokenId, String sessionId, String scope, String name, String picture) {
       this.iss = iss;
       this.sub = sub;
       this.aud = aud;
       this.exp = exp;
       this.iat = iat;
       this.auth_time = auth_time;
       this.email = email;
       this.mobile = mobile;
       this.userId = userId;
       this.tokenId = tokenId;
       this.sessionId = sessionId;
       this.scope = scope;
       this.name = name;
       this.picture = picture;
  }

   @Override
   public String toString() {
       return "UserDataVerified{" +
               "iss='" + iss + '\'' +
               ", sub='" + sub + '\'' +
               ", aud='" + aud + '\'' +
               ", exp='" + exp + '\'' +
               ", iat='" + iat + '\'' +
               ", auth_time='" + auth_time + '\'' +
               ", tokenId='" + tokenId + '\'' +
               ", sessionId='" + sessionId + '\'' +
               ", scope='" + scope + '\'' +
               ", email='" + email + '\'' +
               ", name='" + name + '\'' +
               ", picture='" + picture + '\'' +
               ", mobile='" + mobile + '\'' +
               ", userId='" + userId + '\'' +
               '}';
   }
 }         
Once you have the user details, you should save that information in your app’s database and use it to skip the login process next time the user launches your app.

Note:

  • It is recommended that you don’t use the email address to identify a user. Instead, use the userId.
  • If your app does not have a backend server, you can get the userId on the client using userData.getUserId().
  • If your app has a backend server, you can call the verify token API and get the userId as a response with the user data.

 

×
Text copied to clipboard
Questions? Please reach out to us at dev-support@now.gg