Skip to content
This repository was archived by the owner on Jun 30, 2023. It is now read-only.

Commit b3ec380

Browse files
Clément Denistangiel
authored andcommitted
Handle scope conjunctions properly
1 parent 7374cbd commit b3ec380

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

endpoints-framework/src/main/java/com/google/api/server/spi/config/model/AuthScopeRepository.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,13 @@ private static ImmutableMap<String, String> loadScopeDescriptions(String fileNam
4141

4242
public AuthScopeRepository() {
4343
//userinfo.email should always be requested, as it is required for authentication
44-
add(Constant.API_EMAIL_SCOPE);
45-
}
46-
47-
public void add(String scope) {
48-
descriptionsByScope
49-
.put(scope, MoreObjects.firstNonNull(GOOGLE_SCOPE_DESCRIPTIONS.get(scope), scope));
44+
add(AuthScopeExpressions.interpret(Constant.API_EMAIL_SCOPE));
5045
}
5146

5247
public void add(AuthScopeExpression scopeExpression) {
53-
for (String scope : AuthScopeExpressions.encode(scopeExpression)) {
54-
add(scope);
48+
for (String scope : scopeExpression.getAllScopes()) {
49+
String description = MoreObjects.firstNonNull(GOOGLE_SCOPE_DESCRIPTIONS.get(scope), scope);
50+
descriptionsByScope.put(scope, description);
5551
}
5652
}
5753

endpoints-framework/src/test/resources/com/google/api/server/spi/discovery/custom_scopes.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@
9898
"email"
9999
]
100100
},
101+
"complexScopeExpression": {
102+
"httpMethod": "POST",
103+
"id": "customScopes.customScopesEndpoint.complexScopeExpression",
104+
"path": "complexScopeExpression",
105+
"scopes": [
106+
"email profile",
107+
"https://mail.google.com/"
108+
]
109+
},
101110
"foo": {
102111
"httpMethod": "POST",
103112
"id": "customScopes.customScopesEndpoint.foo",
@@ -108,16 +117,6 @@
108117
"scopes": [
109118
"https://mail.google.com/"
110119
]
111-
},
112-
"multipleScopes": {
113-
"httpMethod": "POST",
114-
"id": "customScopes.customScopesEndpoint.multipleScopes",
115-
"path": "multipleScopes",
116-
"scopes": [
117-
"email",
118-
"profile",
119-
"https://mail.google.com/"
120-
]
121120
}
122121
}
123122
}

test-utils/src/main/java/com/google/api/server/spi/testing/CustomScopesEndpoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public Foo foo() {
2020
public Bar bar() {
2121
return null;
2222
}
23-
@ApiMethod(scopes = {"email", "profile", "https://mail.google.com/"})
24-
public void multipleScopes() {}
23+
@ApiMethod(scopes = {"email profile", "https://mail.google.com/"})
24+
public void complexScopeExpression() {}
2525
}

0 commit comments

Comments
 (0)