Skip to content

Commit

Permalink
granular_scopes added to DebugTokenInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Rasche authored and nbartels committed Jan 11, 2022
1 parent 9961f1b commit aa4ecf8
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/main/java/com/restfb/FacebookClient.java
Expand Up @@ -776,6 +776,12 @@ class DebugTokenInfo extends AbstractFacebookType {
@Facebook
private List<String> scopes = new ArrayList<>();

/**
* List of granular permissions that the user has granted for this app in this access token.
*/
@Facebook("granular_scopes")
private List<GranularScope> granularScopes = new ArrayList<>();

@Facebook
private String type;

Expand Down Expand Up @@ -851,6 +857,15 @@ public List<String> getScopes() {
return unmodifiableList(scopes);
}

/**
* List of granular scopes the access token 'contains'
*
* @return list of granular scopes
*/
public List<GranularScope> getGranularScopes() {
return unmodifiableList(granularScopes);
}

/**
* General metadata associated with the access token. Can contain data like 'sso', 'auth_type', 'auth_nonce'
*
Expand All @@ -874,6 +889,41 @@ public String getType() {
}
}

class GranularScope extends AbstractFacebookType {

private static final long serialVersionUID = 1L;

/**
* The permission granted by the user.
*/
@Facebook
private String scope;

/**
* The target ids of Pages, Groups, or business assets the user granted the above permission for.
*/
@Facebook("target_ids")
private List<String> targetIds = new ArrayList<>();

/**
* The permission granted by the user.
*
* @return The permission granted by the user.
*/
public String getScope() {
return scope;
}

/**
* The target ids of Pages, Groups, or business assets the user granted the above permission for.
*
* @return The target ids of Pages, Groups, or business assets the user granted the above permission for.
*/
public List<String> getTargetIds() {
return unmodifiableList(targetIds);
}
}

class DebugTokenError extends AbstractFacebookType {

private static final long serialVersionUID = 1L;
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/restfb/types/DebugTokenInfoTest.java
Expand Up @@ -63,4 +63,22 @@ void withExpires() {
assertEquals("1234567890", exampleDebugTokenInfo.getAppId());
assertEquals(1561330800000L, exampleDebugTokenInfo.getExpiresAt().getTime());
}

@Test
void testJsonWithGranularScopes() {
FacebookClient.DebugTokenInfo exampleDebugTokenInfo =
createJsonMapper().toJavaObject(jsonFromClasspath("debug-token-info-3"), FacebookClient.DebugTokenInfo.class);
assertNotNull(exampleDebugTokenInfo);
assertNotNull(exampleDebugTokenInfo.getGranularScopes());
assertEquals(2, exampleDebugTokenInfo.getGranularScopes().size());

assertEquals("pages_show_list", exampleDebugTokenInfo.getGranularScopes().get(0).getScope());
assertNotNull(exampleDebugTokenInfo.getGranularScopes().get(0).getTargetIds());
assertEquals(0, exampleDebugTokenInfo.getGranularScopes().get(0).getTargetIds().size());

assertEquals("instagram_basic", exampleDebugTokenInfo.getGranularScopes().get(1).getScope());
assertNotNull(exampleDebugTokenInfo.getGranularScopes().get(1).getTargetIds());
assertEquals(1, exampleDebugTokenInfo.getGranularScopes().get(1).getTargetIds().size());
assertEquals("{connected-ig-user-id}", exampleDebugTokenInfo.getGranularScopes().get(1).getTargetIds().get(0));
}
}
25 changes: 25 additions & 0 deletions src/test/resources/json/debug-token-info-3.json
@@ -0,0 +1,25 @@
{
"app_id": "{app-id}",
"type": "USER",
"application": "{app-name}",
"data_access_expires_at": 1649504517,
"expires_at": 1641733200,
"is_valid": true,
"scopes": [
"pages_show_list",
"instagram_basic",
"public_profile"
],
"granular_scopes": [
{
"scope": "pages_show_list"
},
{
"scope": "instagram_basic",
"target_ids": [
"{connected-ig-user-id}"
]
}
],
"user_id": "{user-id}"
}

0 comments on commit aa4ecf8

Please sign in to comment.