menu arrow_back close search On Github

Access user information

  1. Home
  2. Android SDK integration
  3. Access user information

Add claims

The SDK allows for two ways of accessing user information. Either by requesting and accessing an IdToken or by making a network call using getUserInfo(…).

The presence of the fields depend on the scope and claim variables that were given at sign-in time. Set the scope to access these fields and set the claims to make sure that the user has something in these fields. See docs.telenordigital.com/apis/connect/id/authentication.html for more details.

To set claims use the setClaims method on the ConnectLoginButton.

@Override
public void onCreate(Bundle savedInstanceState) {
    // ...
    ConnectLoginButton button = (ConnectLoginButton) findViewById(R.id.login_button);
    button.setLoginScopeTokens("profile");
    button.setClaims(new Claims(Claims.PHONE_NUMBER, Claims.EMAIL));
}

Access User Information by IdToken

When authenticating the user make sure to request the openid scope:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_in);

    ConnectSdk.sdkInitialize(getApplicationContext());
    ConnectLoginButton loginButton = (ConnectLoginButton) findViewById(R.id.login_button);
    loginButton.setLoginScopeTokens("openid");
}

When the user has authenticated you call:

IdToken idToken = ConnectSdk.getIdToken();

And access user information by calling for example:

String email = idToken.getEmail();

Access User Information by getUserInfo(…)

You can also access user information by making a network call using getUserInfo(…):

ConnectSdk.getUserInfo(new Callback<UserInfo>() {
    @Override
    public void success(UserInfo userInfo, Response response) {
        // app code
    }

    @Override
    public void failure(RetrofitError error) {
        // app code
    }
});
Edit this page