com.auth0.core.Token Java Examples

The following examples show how to use com.auth0.core.Token. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProfileActivity.java    From endpoints-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);
    UserProfile profile = getIntent().getParcelableExtra(Lock.AUTHENTICATION_ACTION_PROFILE_PARAMETER);
    Token token = getIntent().getParcelableExtra(Lock.AUTHENTICATION_ACTION_TOKEN_PARAMETER);
    TextView greetingTextView = (TextView) findViewById(R.id.welcome_message);
    greetingTextView.setText("Welcome " + profile.getName());
    ImageView profileImageView = (ImageView) findViewById(R.id.profile_image);
    if (profile.getPictureURL() != null) {
        ImageLoader.getInstance().displayImage(profile.getPictureURL(), profileImageView);
    }

    client = new AsyncHttpClient();
    client.addHeader("Authorization", "Bearer " + token.getIdToken());
    Button callAPIButton = (Button) findViewById(R.id.call_api_button);
    callAPIButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            callAPI();
        }
    });
}
 
Example #2
Source File: LockReactModule.java    From react-native-lock with MIT License 6 votes vote down vote up
private boolean invokeAuthCallback(String err, UserProfile profile, Token token) {
    if (authCallback == null) {
        Log.e(TAG, "Invalid/old callback called! err: " + err + " profile: " + profile + " token: " + token);
        return false;
    }

    authenticationReceiver.unregisterFrom(this.broadcastManager);

    UserProfileBridge userProfileBridge = new UserProfileBridge(profile);
    TokenBridge tokenBridge = new TokenBridge(token);

    authCallback.invoke(err, userProfileBridge.toMap(), tokenBridge.toMap());
    authCallback = null;

    return true;
}
 
Example #3
Source File: LoginActivity.java    From AvI with MIT License 5 votes vote down vote up
private void logTokens(UserProfile userProfile, Token accessToken){
    Log.i("smuk", "User " + userProfile.getName() + " logged in");
    Log.i("smuk", "Email  " + userProfile.getEmail());
    Log.i("smuk", "Id " + userProfile.getId());
    Log.i("smuk", "Nick " + userProfile.getNickname());
    Log.i("smuk", "PictureUrl " + userProfile.getPictureURL());
    Log.i("smuk", "extra info " + userProfile.getExtraInfo());
    Log.i("smuk", "User identities " + userProfile.getIdentities());

    Log.i("smuk", "AccessToken " + accessToken.getAccessToken());
    Log.i("smuk", "RefreshToken " + accessToken.getRefreshToken());
    Log.i("smuk", "IdToken " + accessToken.getIdToken());
    Log.i("smuk", "Type " + accessToken.getType());
}
 
Example #4
Source File: LockReactModuleTest.java    From react-native-lock with MIT License 5 votes vote down vote up
@Test
public void shouldAuthenticateSuccessfully() throws Exception {
    module.init(initOptions("CLIENT_ID", "samples.auth0.com", null));
    module.show(null, callback);

    Map<String, Object> values = new HashMap<>();
    values.put("user_id", "user-id-value");
    values.put("name", "name-value");
    values.put("extra_key", "extra-key-value");
    UserProfile profile = new UserProfile(values);

    Token token = new Token("id-token", "access-token", "token-type", "refresh-token");

    Intent result = new Intent(Lock.AUTHENTICATION_ACTION)
            .putExtra(Lock.AUTHENTICATION_ACTION_PROFILE_PARAMETER, profile)
            .putExtra(Lock.AUTHENTICATION_ACTION_TOKEN_PARAMETER, token);

    module.authenticationReceiver.onReceive(reactContext, result);

    UserProfileBridge profileBridge = new UserProfileBridge(profile);
    TokenBridge tokenBridge = new TokenBridge(token);

    ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);

    verify(callback).invoke(captor.capture());

    List<Object> list = captor.getAllValues();
    assertThat(list.get(0), is(nullValue()));
    assertThat((WritableMap) list.get(1), is(equalTo(profileBridge.toMap())));
    assertThat((WritableMap) list.get(2), is(equalTo(tokenBridge.toMap())));

    verifyNoMoreInteractions(callback);
}
 
Example #5
Source File: TokenBridgeTest.java    From react-native-lock with MIT License 5 votes vote down vote up
@Test
public void testAll() throws Exception {
    Token token = new Token("id-token-value", "access-token-value", "type-value", "refresh-token-value");
    TokenBridge tokenBridge = new TokenBridge(token);

    ReadableMap map = tokenBridge.toMap();

    assertThat(map.getString("idToken"), is(equalTo("id-token-value")));
    assertThat(map.getString("accessToken"), is(equalTo("access-token-value")));
    assertThat(map.getString("type"), is(equalTo("type-value")));
    assertThat(map.getString("refreshToken"), is(equalTo("refresh-token-value")));
}
 
Example #6
Source File: TokenBridge.java    From react-native-lock with MIT License 4 votes vote down vote up
public TokenBridge(@Nullable Token token) {
    this.token = token;
}
 
Example #7
Source File: LockReactModule.java    From react-native-lock with MIT License 4 votes vote down vote up
@Override
public void onAuthentication(@NonNull UserProfile profile, @NonNull Token token) {
    Log.d(TAG, "User " + profile.getName() + " with token " + token.getIdToken());
    authCallbackSuccess(profile, token);
}
 
Example #8
Source File: LockReactModule.java    From react-native-lock with MIT License 4 votes vote down vote up
private boolean authCallbackSuccess(UserProfile profile, Token token) {
    return invokeAuthCallback(null, profile, token);
}