Skip to content

Commit ab09506

Browse files
committed
Merge remote-tracking branch 'oauth/master'
* oauth/master: Bump scribe version to 6.9.0 Upgrade bazlets to latest master to build with 3.1.3 API Add support for GitHub Enterprise OAuth Init: Default to yes only for currently configured providers Bump required Bazel version to 2.1.0 Upgrade bazlets to latest stable-3.0 to build with 3.0.7 API Upgrade bazlets to latest stable-2.16 to build with 2.16.16 API Documentation: Add missing footer that links to plugin index page Add an empty tools/BUILD file explicitly for Bazel Documentation: Add missing plugin standalone and in-tree testing Upgrade bazlets to latest stable-2.16 Upgrade bazlets to latest master Upgrade bazlets to latest stable-3.0 Upgrade bazlets to latest stable-2.16 Upgrade bazlets to latest stable-2.15 Upgrade bazlets to latest stable-2.14 Replace ExpectedException with assertThrows Add .apt_generated to .gitignore Bump Bazel version to 2.0.0 Upgrade bazlets to latest master to build with 3.1.2 API Upgrade bazlets to latest stable-3.0 to build with 3.0.6 API Upgrade bazlets to latest stable-2.16 to build with 2.16.15 API Upgrade bazlets to latest master to build with 3.1.1 API Upgrade bazlets to latest stable-2.16 to build with 2.16.14 API Upgrade bazlets to latest stable-3.0 to build with 3.0.5 API Fix NullPointerException in init in batch mode Upgrade bazlets to latest master to build with 3.1.0 API Upgrade bazlets to latest stable-3.0 to build with 3.0.4 API Upgrade bazlets to latest stable-2.16 to build with 2.16.13 API Upgrade bazlets to latest master to build with 3.1.0-rc3 API Upgrade bazlets to latest stable-3.0 Upgrade bazlets to latest stable-2.16 Upgrade bazlets to latest stable-2.15 to build with 2.15.18 API Upgrade bazlets to latest stable-2.15 Upgrade bazlets to latest stable-2.14 Bazel: Migrate workspace status script to python Check that root URL is absolute URL Upgrade bazlets to latest master to build with 3.1.0-rc2 API Upgrade bazlets to latest stable-2.16 Upgrade bazlets to latest stable-2.15 Upgrade bazlets to latest stable-2.14 Bump Bazel version to 1.1.0 Upgrade bazlets to latest master to build with 3.1.0-rc1 API Upgrade bazlets to latest master to build with 3.1.0-rc0 API Remove bazel-genfiles from .gitignore Replace bazel-genfiles with bazel-bin in documentation Upgrade bazlets to latest stable-3.0 to build with 3.0.3 API Bump bazel version to 1.0.0 Add support for GitHub Enterprise OAuth Upgrade bazlets to latest stable-2.16 to build with 2.16.12 API Upgrade bazlets to latest stable-2.15 to build with 2.15.17 API Switch required bazel version to 0.29.1 Upgrade bazlets to latest master Upgrade bazlets to latest stable-3.0 Upgrade bazlets to latest stable-2.16 Upgrade bazlets to latest stable-2.15 Bump required bazel version to 1.0.0rc2 Upgrade bazlets to latest stable-2.14 Upgrade bazlets to latest stable-2.15 Upgrade bazlets to latest stable-2.14 Bazel: Add fixes for --incompatible_load_java_rules_from_bzl Upgrade bazlets to latest stable-3.0 to build with 3.0.2 API Upgrade bazlets to latest stable-2.16 to build with 2.16.11.1 API Upgrade bazlets to latest stable-2.15 to build with 2.15.16 API Upgrade bazlets to latest stable-2.15 to build with 2.15.15 API Upgrade bazlets to latest master Upgrade bazlets to latest stable-3.0 Upgrade bazlets to latest stable-2.16 to build with 2.16.10 API Upgrade bazlets to latest stable-3.0 to build with 3.0.1 API Upgrade bazlets to latest stable-2.16 Upgrade bazlets to latest stable-2.15 Upgrade bazlets to latest stable-2.14 Upgrade bazlets to latest stable-2.15 Upgrade bazlets to latest stable-2.14 Upgrade bazlets to latest stable-2.16 to build with 2.16.9 API Upgrade bazlets to latest stable-2.15 Upgrade bazlets to latest stable-2.14 Upgrade bazlets to latest stable-2.15 to build with 2.15.14 API Change-Id: Ib4e1a9609cc9049da5a609bfac7a1b6ba23514f3
2 parents 0f807f6 + 7b4f988 commit ab09506

37 files changed

+935
-1020
lines changed

.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
build --workspace_status_command=./tools/workspace-status.sh
1+
build --workspace_status_command="python ./tools/workspace_status.py"
22
test --build_tests_only

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.1.0

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
/.apt_generated
12
/.classpath
23
/.project
34
/.settings
45
/bazel-bin
5-
/bazel-genfiles
66
/bazel-gerrit-oauth-provider
77
/bazel-out
88
/bazel-testlogs

BUILD

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@rules_java//java:defs.bzl", "java_library")
12
load("//tools/bzl:junit.bzl", "junit_tests")
23
load(
34
"//tools/bzl:plugin.bzl",
@@ -19,7 +20,8 @@ gerrit_plugin(
1920
resources = glob(["src/main/resources/**/*"]),
2021
deps = [
2122
"@commons-codec//jar:neverlink",
22-
"@scribe//jar",
23+
"@jackson-databind//jar",
24+
"@scribejava-core//jar",
2325
],
2426
)
2527

@@ -38,6 +40,6 @@ java_library(
3840
visibility = ["//visibility:public"],
3941
exports = PLUGIN_DEPS + PLUGIN_TEST_DEPS + [
4042
":gerrit-oauth-provider__plugin",
41-
"@scribe//jar",
43+
"@mockito//jar",
4244
],
4345
)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ following:
4040
Install
4141
-------
4242

43-
Copy the `bazel-genfiles/oauth.jar` to
43+
Copy the `bazel-bin/oauth.jar` to
4444
`$gerrit_site/plugins` and re-run init to configure it:
4545

4646
```

WORKSPACE

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ workspace(name = "com_github_davido_gerrit_oauth_provider")
33
load("//:bazlets.bzl", "load_bazlets")
44

55
load_bazlets(
6-
commit = "d826d85285bb22d3fe817fe165a7e1d3472f65fa",
6+
commit = "f30a992da9fc855dce819875afb59f9dd6f860cd",
77
#local_path = "/home/<user>/projects/bazlets",
88
)
99

1010
# Snapshot Plugin API
11-
load(
12-
"@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl",
13-
"gerrit_api_maven_local",
14-
)
11+
#load(
12+
# "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl",
13+
# "gerrit_api_maven_local",
14+
#)
1515

1616
# Load snapshot Plugin API
17-
gerrit_api_maven_local()
17+
#gerrit_api_maven_local()
1818

1919
# Release Plugin API
20-
#load(
21-
# "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl",
22-
# "gerrit_api",
23-
#)
20+
load(
21+
"@com_googlesource_gerrit_bazlets//:gerrit_api.bzl",
22+
"gerrit_api",
23+
)
2424

25-
#gerrit_api()
25+
gerrit_api()
2626

2727
load(":external_plugin_deps.bzl", "external_plugin_deps")
2828

external_plugin_deps.bzl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
load("//tools/bzl:maven_jar.bzl", "maven_jar")
22

33
def external_plugin_deps(omit_commons_codec = True):
4+
JACKSON_VERS = "2.10.2"
45
maven_jar(
5-
name = "scribe",
6-
artifact = "org.scribe:scribe:1.3.7",
7-
sha1 = "583921bed46635d9f529ef5f14f7c9e83367bc6e",
6+
name = "scribejava-core",
7+
artifact = "com.github.scribejava:scribejava-core:6.9.0",
8+
sha1 = "ed761f450d8382f75787e8fee9ae52e7ec768747",
9+
)
10+
maven_jar(
11+
name = "jackson-annotations",
12+
artifact = "com.fasterxml.jackson.core:jackson-annotations:" + JACKSON_VERS,
13+
sha1 = "3a13b6105946541b8d4181a0506355b5fae63260",
14+
)
15+
maven_jar(
16+
name = "jackson-databind",
17+
artifact = "com.fasterxml.jackson.core:jackson-databind:" + JACKSON_VERS,
18+
sha1 = "0528de95f198afafbcfb0c09d2e43b6e0ea663ec",
19+
deps = [
20+
"@jackson-annotations//jar",
21+
],
822
)
923
if not omit_commons_codec:
1024
maven_jar(

src/main/java/com/googlesource/gerrit/plugins/oauth/AirVantageApi.java

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,31 @@
1414

1515
package com.googlesource.gerrit.plugins.oauth;
1616

17-
import static java.lang.String.format;
18-
19-
import org.scribe.builder.api.DefaultApi20;
20-
import org.scribe.extractors.AccessTokenExtractor;
21-
import org.scribe.extractors.JsonTokenExtractor;
22-
import org.scribe.model.OAuthConfig;
23-
import org.scribe.model.Verb;
24-
import org.scribe.oauth.OAuthService;
17+
import com.github.scribejava.core.builder.api.DefaultApi20;
18+
import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor;
19+
import com.github.scribejava.core.extractors.TokenExtractor;
20+
import com.github.scribejava.core.model.OAuth2AccessToken;
21+
import com.github.scribejava.core.oauth2.bearersignature.BearerSignature;
22+
import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter;
2523

2624
public class AirVantageApi extends DefaultApi20 {
27-
28-
private static final String AUTHORIZE_URL =
29-
"https://eu.airvantage.net/api/oauth/authorize?client_id=%s&response_type=code";
30-
private static final String ACCESS_TOKEN_ENDPOINT = "https://eu.airvantage.net/api/oauth/token";
31-
3225
@Override
33-
public String getAuthorizationUrl(OAuthConfig config) {
34-
return format(AUTHORIZE_URL, config.getApiKey());
26+
public String getAuthorizationBaseUrl() {
27+
return "https://eu.airvantage.net/api/oauth/authorize";
3528
}
3629

3730
@Override
3831
public String getAccessTokenEndpoint() {
39-
return ACCESS_TOKEN_ENDPOINT;
40-
}
41-
42-
@Override
43-
public Verb getAccessTokenVerb() {
44-
return Verb.POST;
32+
return "https://eu.airvantage.net/api/oauth/token";
4533
}
4634

4735
@Override
48-
public AccessTokenExtractor getAccessTokenExtractor() {
49-
return new JsonTokenExtractor();
36+
public BearerSignature getBearerSignature() {
37+
return BearerSignatureURIQueryParameter.instance();
5038
}
5139

5240
@Override
53-
public OAuthService createService(OAuthConfig config) {
54-
return new OAuth20ServiceImpl(this, config);
41+
public TokenExtractor<OAuth2AccessToken> getAccessTokenExtractor() {
42+
return OAuth2AccessTokenExtractor.instance();
5543
}
5644
}

src/main/java/com/googlesource/gerrit/plugins/oauth/AirVantageOAuthService.java

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
import static javax.servlet.http.HttpServletResponse.SC_OK;
1919
import static org.slf4j.LoggerFactory.getLogger;
2020

21+
import com.github.scribejava.core.builder.ServiceBuilder;
22+
import com.github.scribejava.core.model.OAuth2AccessToken;
23+
import com.github.scribejava.core.model.OAuthRequest;
24+
import com.github.scribejava.core.model.Response;
25+
import com.github.scribejava.core.model.Verb;
26+
import com.github.scribejava.core.oauth.OAuth20Service;
2127
import com.google.common.base.CharMatcher;
2228
import com.google.gerrit.extensions.annotations.PluginName;
2329
import com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider;
@@ -33,13 +39,7 @@
3339
import com.google.inject.Provider;
3440
import com.google.inject.Singleton;
3541
import java.io.IOException;
36-
import org.scribe.builder.ServiceBuilder;
37-
import org.scribe.model.OAuthRequest;
38-
import org.scribe.model.Response;
39-
import org.scribe.model.Token;
40-
import org.scribe.model.Verb;
41-
import org.scribe.model.Verifier;
42-
import org.scribe.oauth.OAuthService;
42+
import java.util.concurrent.ExecutionException;
4343
import org.slf4j.Logger;
4444

4545
@Singleton
@@ -49,7 +49,7 @@ public class AirVantageOAuthService implements OAuthServiceProvider {
4949
private static final String AV_PROVIDER_PREFIX = "airvantage-oauth:";
5050
private static final String PROTECTED_RESOURCE_URL =
5151
"https://eu.airvantage.net/api/v1/users/current";
52-
private final OAuthService service;
52+
private final OAuth20Service service;
5353

5454
@Inject
5555
AirVantageOAuthService(
@@ -60,59 +60,68 @@ public class AirVantageOAuthService implements OAuthServiceProvider {
6060
String canonicalWebUrl = CharMatcher.is('/').trimTrailingFrom(urlProvider.get()) + "/";
6161

6262
service =
63-
new ServiceBuilder()
64-
.provider(AirVantageApi.class)
65-
.apiKey(cfg.getString(InitOAuth.CLIENT_ID))
63+
new ServiceBuilder(cfg.getString(InitOAuth.CLIENT_ID))
6664
.apiSecret(cfg.getString(InitOAuth.CLIENT_SECRET))
6765
.callback(canonicalWebUrl + "oauth")
68-
.build();
66+
.build(new AirVantageApi());
6967
}
7068

7169
@Override
7270
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
7371
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
74-
Token t = new Token(token.getToken(), token.getSecret(), token.getRaw());
72+
OAuth2AccessToken t = new OAuth2AccessToken(token.getToken(), token.getRaw());
7573
service.signRequest(t, request);
76-
Response response = request.send();
77-
if (response.getCode() != SC_OK) {
78-
throw new IOException(
79-
String.format(
80-
"Status %s (%s) for request %s",
81-
response.getCode(), response.getBody(), request.getUrl()));
82-
}
83-
JsonElement userJson = JSON.newGson().fromJson(response.getBody(), JsonElement.class);
84-
if (log.isDebugEnabled()) {
85-
log.debug("User info response: {}", response.getBody());
86-
}
87-
if (userJson.isJsonObject()) {
88-
JsonObject jsonObject = userJson.getAsJsonObject();
89-
JsonElement id = jsonObject.get("uid");
90-
if (id == null || id.isJsonNull()) {
91-
throw new IOException("Response doesn't contain uid field");
74+
75+
JsonElement userJson = null;
76+
try (Response response = service.execute(request)) {
77+
if (response.getCode() != SC_OK) {
78+
throw new IOException(
79+
String.format(
80+
"Status %s (%s) for request %s",
81+
response.getCode(), response.getBody(), request.getUrl()));
9282
}
93-
JsonElement email = jsonObject.get("email");
94-
JsonElement name = jsonObject.get("name");
95-
return new OAuthUserInfo(
96-
AV_PROVIDER_PREFIX + id.getAsString(),
97-
null,
98-
email.getAsString(),
99-
name.getAsString(),
100-
id.getAsString());
83+
userJson = JSON.newGson().fromJson(response.getBody(), JsonElement.class);
84+
if (log.isDebugEnabled()) {
85+
log.debug("User info response: {}", response.getBody());
86+
}
87+
if (userJson.isJsonObject()) {
88+
JsonObject jsonObject = userJson.getAsJsonObject();
89+
JsonElement id = jsonObject.get("uid");
90+
if (id == null || id.isJsonNull()) {
91+
throw new IOException("Response doesn't contain uid field");
92+
}
93+
JsonElement email = jsonObject.get("email");
94+
JsonElement name = jsonObject.get("name");
95+
return new OAuthUserInfo(
96+
AV_PROVIDER_PREFIX + id.getAsString(),
97+
null,
98+
email.getAsString(),
99+
name.getAsString(),
100+
id.getAsString());
101+
}
102+
} catch (ExecutionException | InterruptedException e) {
103+
throw new RuntimeException("Cannot retrieve user info resource", e);
101104
}
102105

103106
throw new IOException(String.format("Invalid JSON '%s': not a JSON Object", userJson));
104107
}
105108

106109
@Override
107110
public OAuthToken getAccessToken(OAuthVerifier rv) {
108-
Verifier vi = new Verifier(rv.getValue());
109-
Token to = service.getAccessToken(null, vi);
110-
return new OAuthToken(to.getToken(), to.getSecret(), to.getRawResponse());
111+
try {
112+
OAuth2AccessToken accessToken = service.getAccessToken(rv.getValue());
113+
return new OAuthToken(
114+
accessToken.getAccessToken(), accessToken.getTokenType(), accessToken.getRawResponse());
115+
} catch (InterruptedException | ExecutionException | IOException e) {
116+
String msg = "Cannot retrieve access token";
117+
log.error(msg, e);
118+
throw new RuntimeException(msg, e);
119+
}
111120
}
112121

113122
@Override
114123
public String getAuthorizationUrl() {
115-
return service.getAuthorizationUrl(null);
124+
return service.getAuthorizationUrl();
116125
}
117126

118127
@Override

0 commit comments

Comments
 (0)