com.auth0.core.UserProfile Java Examples

The following examples show how to use com.auth0.core.UserProfile. 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: UserProfileBridgeTest.java    From react-native-lock with MIT License 6 votes vote down vote up
@Test
public void shouldBridgeMetadata() throws Exception {
    final HashMap<String, Object> user = Maps.newHashMap();
    user.put("first_name", "John");
    user.put("last_name", "Doe");
    user.put("friend_count", 14);

    final HashMap<String, Object> app = Maps.newHashMap();
    app.put("subscription", "bronze");

    final UserProfile profile = withMetadata(INFO_AUTH0_COM, user, app);
    final ReadableMap map = bridge(profile);

    assertThat(map.getString(EMAIL), equalTo(INFO_AUTH0_COM));

    final ReadableMap userMetadata = map.getMap(USER_METADATA);
    assertThat(userMetadata.getString("first_name"), equalTo("John"));
    assertThat(userMetadata.getString("last_name"), equalTo("Doe"));
    assertThat(userMetadata.getInt("friend_count"), equalTo(14));

    final ReadableMap appMetadata = map.getMap(APP_METADATA);
    assertThat(appMetadata.getString("subscription"), equalTo("bronze"));
}
 
Example #4
Source File: UserProfileBridgeTest.java    From react-native-lock with MIT License 6 votes vote down vote up
@Test
public void shouldBridgeIdentity() throws Exception {
    final UserProfile profile = withIdentities(INFO_AUTH0_COM, "facebook");
    final ReadableMap map = bridge(profile);

    assertThat(map.getString(EMAIL), equalTo(profile.getEmail()));

    final ReadableArray identities = map.getArray("identities");
    assertThat(identities.size(), is(1));

    final ReadableMap identityMap = identities.getMap(0);
    final UserIdentity identity = profile.getIdentities().get(0);
    assertThat(identityMap.getString("provider"), equalTo(identity.getProvider()));
    assertThat(identityMap.getString("connection"), equalTo(identity.getConnection()));
    assertThat(identityMap.getString("userId"), equalTo(identity.getId()));
    assertThat(identityMap.getBoolean("social"), equalTo(identity.isSocial()));
    assertThat(identityMap.getMap("profileData"), is(notNullValue()));
}
 
Example #5
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 #6
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 #7
Source File: UserProfileBridgeTest.java    From react-native-lock with MIT License 5 votes vote down vote up
@Test
public void shouldBridgeBasicProfile() throws Exception {
    final UserProfile profile = basic(INFO_AUTH0_COM);
    final ReadableMap map = bridge(profile);
    assertThat(map.getString(EMAIL), equalTo(profile.getEmail()));
    assertThat(map.getString(USER_ID), equalTo(profile.getId()));
    assertThat(map.getString(NAME), equalTo(profile.getName()));
    assertThat(map.getString(NICKNAME), equalTo(profile.getNickname()));
    assertThat(sdf.parse(map.getString(CREATED_AT)), equalTo(profile.getCreatedAt()));
    assertThat(map.getString(PICTURE), equalTo(profile.getPictureURL()));
}
 
Example #8
Source File: UserProfileBridgeTest.java    From react-native-lock with MIT License 5 votes vote down vote up
@Test
public void shouldBridgeNonBasicProfile() throws Exception {
    final UserProfile profile = withOtherRootAttributes(INFO_AUTH0_COM);
    final ReadableMap map = bridge(profile);

    assertThat(map.getString(EMAIL), equalTo(profile.getEmail()));
    assertThat(map.getInt("logins_count"), equalTo(profile.getExtraInfo().get("logins_count")));
}
 
Example #9
Source File: UserProfileBridgeTest.java    From react-native-lock with MIT License 5 votes vote down vote up
private UserProfile withIdentities(String email, String...providers) {
    final Map<String, Object> json = defaultJson(email);
    List<Map<String, Object>> identities = new ArrayList<>();
    for (String provider: providers) {
        identities.add(identityJson(provider));
    }
    json.put("identities", identities);
    return new UserProfile(json);
}
 
Example #10
Source File: UserProfileBridgeTest.java    From react-native-lock with MIT License 5 votes vote down vote up
private UserProfile withMetadata(String email, Map<String, Object> userMetadata, Map<String, Object> appMetadata) {
    Map<String, Object> json = defaultJson(email);
    if (userMetadata != null) {
        json.put("user_metadata", userMetadata);
    }
    if (appMetadata != null) {
        json.put("app_metadata", appMetadata);
    }
    return new UserProfile(json);
}
 
Example #11
Source File: UserProfileBridge.java    From react-native-lock with MIT License 4 votes vote down vote up
public UserProfileBridge(@Nullable UserProfile profile) {
    // use ISO 8601 international standard date/time format
    this.formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
    this.formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
    this.profile = profile;
}
 
Example #12
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 #13
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);
}
 
Example #14
Source File: UserProfileBridgeTest.java    From react-native-lock with MIT License 4 votes vote down vote up
private ReadableMap bridge(UserProfile profile) {
    return new UserProfileBridge(profile).toMap();
}
 
Example #15
Source File: UserProfileBridgeTest.java    From react-native-lock with MIT License 4 votes vote down vote up
private UserProfile basic(String email) {
    return new UserProfile(defaultJson(email));
}
 
Example #16
Source File: UserProfileBridgeTest.java    From react-native-lock with MIT License 4 votes vote down vote up
private UserProfile withOtherRootAttributes(String email) {
    final Map<String, Object> json = defaultJson(email);
    json.put("logins_count", randomizer.integer());
    return new UserProfile(json);
}