[Java][jersey2] Add debugging to OAuth (#6757)

* add debugging to oauth

* use fine instead
This commit is contained in:
William Cheng
2020-06-26 16:25:55 +08:00
committed by GitHub
parent 8b9c070e5d
commit 919b3b6bef
6 changed files with 414 additions and 384 deletions

View File

@@ -461,7 +461,7 @@ public class ApiClient {
public ApiClient setOauthCredentials(String clientId, String clientSecret) {
for (Authentication auth : authentications.values()) {
if (auth instanceof OAuth) {
((OAuth) auth).setCredentials(clientId, clientSecret);
((OAuth) auth).setCredentials(clientId, clientSecret, isDebugging());
return this;
}
}

View File

@@ -91,6 +91,7 @@ public class OAuth implements Authentication {
public synchronized OAuth2AccessToken obtainAccessToken(String refreshToken) throws ApiException {
if (service == null) {
log.log(Level.FINE, "service is null in obtainAccessToken.");
return null;
}
try {
@@ -115,6 +116,9 @@ public class OAuth implements Authentication {
break;
case application:
accessToken = service.getAccessTokenClientCredentialsGrant(scope);
break;
default:
log.log(Level.SEVERE, "Invalid flow in obtainAccessToken: " + flow);
}
} catch (OAuthException | InterruptedException | ExecutionException | IOException e) {
throw new ApiException(e);
@@ -141,10 +145,16 @@ public class OAuth implements Authentication {
return this;
}
public OAuth setCredentials(String clientId, String clientSecret) {
public OAuth setCredentials(String clientId, String clientSecret, Boolean debug) {
if (Boolean.TRUE.equals(debug)) {
service = new ServiceBuilder(clientId)
.apiSecret(clientSecret).debug()
.build(authApi);
} else {
service = new ServiceBuilder(clientId)
.apiSecret(clientSecret)
.build(authApi);
}
return this;
}

View File

@@ -379,7 +379,7 @@ public class ApiClient {
public ApiClient setOauthCredentials(String clientId, String clientSecret) {
for (Authentication auth : authentications.values()) {
if (auth instanceof OAuth) {
((OAuth) auth).setCredentials(clientId, clientSecret);
((OAuth) auth).setCredentials(clientId, clientSecret, isDebugging());
return this;
}
}

View File

@@ -102,6 +102,7 @@ public class OAuth implements Authentication {
public synchronized OAuth2AccessToken obtainAccessToken(String refreshToken) throws ApiException {
if (service == null) {
log.log(Level.FINE, "service is null in obtainAccessToken.");
return null;
}
try {
@@ -126,6 +127,9 @@ public class OAuth implements Authentication {
break;
case application:
accessToken = service.getAccessTokenClientCredentialsGrant(scope);
break;
default:
log.log(Level.SEVERE, "Invalid flow in obtainAccessToken: " + flow);
}
} catch (OAuthException | InterruptedException | ExecutionException | IOException e) {
throw new ApiException(e);
@@ -152,10 +156,16 @@ public class OAuth implements Authentication {
return this;
}
public OAuth setCredentials(String clientId, String clientSecret) {
public OAuth setCredentials(String clientId, String clientSecret, Boolean debug) {
if (Boolean.TRUE.equals(debug)) {
service = new ServiceBuilder(clientId)
.apiSecret(clientSecret).debug()
.build(authApi);
} else {
service = new ServiceBuilder(clientId)
.apiSecret(clientSecret)
.build(authApi);
}
return this;
}

View File

@@ -458,7 +458,7 @@ public class ApiClient {
public ApiClient setOauthCredentials(String clientId, String clientSecret) {
for (Authentication auth : authentications.values()) {
if (auth instanceof OAuth) {
((OAuth) auth).setCredentials(clientId, clientSecret);
((OAuth) auth).setCredentials(clientId, clientSecret, isDebugging());
return this;
}
}

View File

@@ -102,6 +102,7 @@ public class OAuth implements Authentication {
public synchronized OAuth2AccessToken obtainAccessToken(String refreshToken) throws ApiException {
if (service == null) {
log.log(Level.FINE, "service is null in obtainAccessToken.");
return null;
}
try {
@@ -126,6 +127,9 @@ public class OAuth implements Authentication {
break;
case application:
accessToken = service.getAccessTokenClientCredentialsGrant(scope);
break;
default:
log.log(Level.SEVERE, "Invalid flow in obtainAccessToken: " + flow);
}
} catch (OAuthException | InterruptedException | ExecutionException | IOException e) {
throw new ApiException(e);
@@ -152,10 +156,16 @@ public class OAuth implements Authentication {
return this;
}
public OAuth setCredentials(String clientId, String clientSecret) {
public OAuth setCredentials(String clientId, String clientSecret, Boolean debug) {
if (Boolean.TRUE.equals(debug)) {
service = new ServiceBuilder(clientId)
.apiSecret(clientSecret).debug()
.build(authApi);
} else {
service = new ServiceBuilder(clientId)
.apiSecret(clientSecret)
.build(authApi);
}
return this;
}