Skip to content

Commit

Permalink
parse extra identity values
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalmaceda committed Mar 14, 2017
1 parent 91297ee commit 6d49ab7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
22 changes: 19 additions & 3 deletions src/main/java/com/auth0/json/mgmt/users/Identity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.auth0.json.mgmt.users;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.*;

import java.util.HashMap;
import java.util.Map;

@SuppressWarnings({"unused", "WeakerAccess"})
@JsonIgnoreProperties(ignoreUnknown = true)
Expand All @@ -21,6 +22,21 @@ public class Identity {
private String accessToken;
@JsonProperty("profileData")
private ProfileData profileData;
private Map<String, Object> values;

This comment has been minimized.

Copy link
@rafalwrzeszcz

rafalwrzeszcz Apr 27, 2017

Is it the right place? Aren't custom properties stored within ProfileData?

Also I think it would be good to add same mechanism to User model, because, when signing up with social provider, entire profile is stored as a root entity.

This comment has been minimized.

Copy link
@lbalmaceda

lbalmaceda Apr 27, 2017

Author Contributor

@rafalwrzeszcz Yes, since the identities can have a profile_data attribute and in the root of the identity the IdP can have more attributes specific to it. We can try to make a generic way to get any IdP specific attribute and the one in profile_data but we are ok with what it is.

We'll add the getValues() for root User in the next release or if you want to tackle it we'll review and merge the PR.


public Identity() {
values = new HashMap<>();
}

@JsonAnySetter
void setValue(String key, Object value) {
values.put(key, value);
}

@JsonAnyGetter
public Map<String, Object> getValues() {
return values;
}

@JsonProperty("connection")
public String getConnection() {
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/com/auth0/json/mgmt/users/IdentityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.*;

public class IdentityTest extends JsonTest<Identity> {

private static final String json = "{\"connection\":\"auth0\",\"user_id\":\"user|123\",\"isSocial\":true,\"provider\":\"oauth\",\"access_token\":\"aTokEn\",\"profileData\":{}}";
private static final String json = "{\"connection\":\"auth0\",\"user_id\":\"user|123\",\"isSocial\":true,\"provider\":\"oauth\",\"access_token\":\"aTokEn\",\"profileData\":{},\"access_token_secret\":\"s3cr3t\"}";

@Test
public void shouldDeserialize() throws Exception {
Expand All @@ -22,5 +21,7 @@ public void shouldDeserialize() throws Exception {
assertThat(identity.getProvider(), is("oauth"));
assertThat(identity.getAccessToken(), is("aTokEn"));
assertThat(identity.getProfileData(), is(notNullValue()));
assertThat(identity.getValues(), is(notNullValue()));
assertThat(identity.getValues(), hasEntry("access_token_secret", (Object) "s3cr3t"));
}
}

0 comments on commit 6d49ab7

Please sign in to comment.