Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit54407f0

Browse files
committed
add ScopeBuilder to easily specify multiple scopes while requesting OAuth2.0 Access Tokens
1 parent0b3c0b7 commit54407f0

File tree

8 files changed

+80
-4
lines changed

8 files changed

+80
-4
lines changed

‎changelog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[SNAPSHOT]
2+
* add ScopeBuilder to easily specify multiple scopes while requesting OAuth2.0 Access Tokens
3+
14
[8.1.0]
25
* add raw Response (with HTTP response code and body) as member to the OAuth2AccessTokenErrorResponse
36
* add possibility to set "" (empty string) as apiSecret

‎pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<dependency>
5555
<groupId>com.fasterxml.jackson.core</groupId>
5656
<artifactId>jackson-databind</artifactId>
57-
<version>2.12.0</version>
57+
<version>2.12.1</version>
5858
</dependency>
5959
<dependency>
6060
<groupId>junit</groupId>
@@ -104,7 +104,7 @@
104104
<dependency>
105105
<groupId>com.puppycrawl.tools</groupId>
106106
<artifactId>checkstyle</artifactId>
107-
<version>8.38</version>
107+
<version>8.39</version>
108108
</dependency>
109109
</dependencies>
110110
</plugin>
@@ -188,6 +188,7 @@
188188
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
189189
<encoding>UTF-8</encoding>
190190
<additionalOptions>-html5</additionalOptions>
191+
<doclint>all,-missing</doclint>
191192
</configuration>
192193
<executions>
193194
<execution>

‎scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
importjava.util.Scanner;
44
importcom.github.scribejava.core.builder.ServiceBuilder;
55
importcom.github.scribejava.apis.LinkedInApi20;
6+
importcom.github.scribejava.core.builder.ScopeBuilder;
67
importcom.github.scribejava.core.model.OAuth2AccessToken;
78
importcom.github.scribejava.core.model.OAuthRequest;
89
importcom.github.scribejava.core.model.Response;
@@ -29,7 +30,7 @@ public static void main(String... args) throws IOException, InterruptedException
2930
finalStringclientSecret ="your client secret";
3031
finalOAuth20Serviceservice =newServiceBuilder(clientId)
3132
.apiSecret(clientSecret)
32-
.defaultScope("r_liteprofiler_emailaddress")// replace with desired scope
33+
.defaultScope(newScopeBuilder("r_liteprofile","r_emailaddress"))// replace with desired scope
3334
.callback("http://example.com/callback")
3435
.build(LinkedInApi20.instance());
3536
finalScannerin =newScanner(System.in);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
packagecom.github.scribejava.core.builder;
2+
3+
importjava.util.Arrays;
4+
importjava.util.Collection;
5+
importjava.util.HashSet;
6+
importjava.util.Set;
7+
8+
/**
9+
* OAuth2.0 Scope Builder. It allows specifying multiple scopes one by one. It will combine them in the single
10+
* space-delimited string. OAuth 2.0 standard specifies space as a delimiter for scopes
11+
* (https://tools.ietf.org/html/rfc6749#section-3.3). If you found API, that do not support spaces, but support
12+
* something else, let ScribeJava know (submit the issue here https://github.com/scribejava/scribejava/issues) and use
13+
* your own concatenated string as a temporary workaround.
14+
*/
15+
publicclassScopeBuilder {
16+
17+
privatefinalSet<String>scopes =newHashSet<>();
18+
19+
publicScopeBuilder() {
20+
}
21+
22+
publicScopeBuilder(Stringscope) {
23+
withScope(scope);
24+
}
25+
26+
publicScopeBuilder(String...scopes) {
27+
withScopes(scopes);
28+
}
29+
30+
publicScopeBuilder(Collection<String>scopes) {
31+
withScopes(scopes);
32+
}
33+
34+
publicfinalScopeBuilderwithScope(Stringscope) {
35+
scopes.add(scope);
36+
returnthis;
37+
}
38+
39+
publicfinalScopeBuilderwithScopes(String...scopes) {
40+
this.scopes.addAll(Arrays.asList(scopes));
41+
returnthis;
42+
}
43+
44+
publicfinalScopeBuilderwithScopes(Collection<String>scopes) {
45+
this.scopes.addAll(scopes);
46+
returnthis;
47+
}
48+
49+
publicStringbuild() {
50+
finalStringBuilderscopeBuilder =newStringBuilder();
51+
for (Stringscope :scopes) {
52+
scopeBuilder.append(' ').append(scope);
53+
}
54+
returnscopeBuilder.substring(1);
55+
}
56+
}

‎scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public ServiceBuilderOAuth20 defaultScope(String defaultScope) {
6868
returnsetScope(defaultScope);
6969
}
7070

71+
@Override
72+
publicServiceBuilderOAuth20defaultScope(ScopeBuilderscopeBuilder) {
73+
returnsetScope(scopeBuilder.build());
74+
}
75+
7176
@Override
7277
publicServiceBuilderOAuth10awithScope(Stringscope) {
7378
returnsetScope(scope);

‎scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,7 @@ public interface ServiceBuilderOAuth20 extends ServiceBuilderCommon {
5151
*/
5252
ServiceBuilderOAuth20defaultScope(StringdefaultScope);
5353

54+
ServiceBuilderOAuth20defaultScope(ScopeBuilderscopeBuilder);
55+
5456
OAuth20Servicebuild(DefaultApi20api);
5557
}

‎scribejava-core/src/main/java/com/github/scribejava/core/oauth/AccessTokenRequestParams.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
packagecom.github.scribejava.core.oauth;
22

3+
importcom.github.scribejava.core.builder.ScopeBuilder;
4+
35
publicclassAccessTokenRequestParams {
6+
47
privatefinalStringcode;
58
privateStringpkceCodeVerifier;
69
privateStringscope;
@@ -23,6 +26,11 @@ public AccessTokenRequestParams scope(String scope) {
2326
returnthis;
2427
}
2528

29+
publicAccessTokenRequestParamsscope(ScopeBuilderscope) {
30+
this.scope =scope.build();
31+
returnthis;
32+
}
33+
2634
publicStringgetCode() {
2735
returncode;
2836
}

‎scribejava-httpclient-ahc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<dependency>
2424
<groupId>org.asynchttpclient</groupId>
2525
<artifactId>async-http-client</artifactId>
26-
<version>2.12.1</version>
26+
<version>2.12.2</version>
2727
</dependency>
2828
<dependency>
2929
<groupId>com.github.scribejava</groupId>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp