Java jersey OAuth2 add support for public client #13827 (#13828)

This commit is contained in:
sbilz
2022-10-31 15:52:42 +01:00
committed by GitHub
parent a04b2623b0
commit fe5601ab9b
12 changed files with 174 additions and 0 deletions

View File

@@ -446,6 +446,22 @@ public class ApiClient extends JavaTimeFormatter {
throw new RuntimeException("No OAuth2 authentication configured!");
}
/**
* Helper method to set the credentials of a public client for the first OAuth2 authentication.
*
* @param clientId the client ID
* @return a {@link org.openapitools.client.ApiClient} object.
*/
public ApiClient setOauthCredentialsForPublicClient(String clientId) {
for (Authentication auth : authentications.values()) {
if (auth instanceof OAuth) {
((OAuth) auth).setCredentialsForPublicClient(clientId, isDebugging());
return this;
}
}
throw new RuntimeException("No OAuth2 authentication configured!");
}
/**
* Helper method to set the password flow for the first OAuth2 authentication.
*

View File

@@ -169,6 +169,19 @@ public class OAuth implements Authentication {
return this;
}
public OAuth setCredentialsForPublicClient(String clientId, Boolean debug) {
if (Boolean.TRUE.equals(debug)) {
service = new ServiceBuilder(clientId)
.apiSecretIsEmptyStringUnsafe().debug()
.build(authApi);
} else {
service = new ServiceBuilder(clientId)
.apiSecretIsEmptyStringUnsafe()
.build(authApi);
}
return this;
}
public OAuth usePasswordFlow(String username, String password) {
this.flow = OAuthFlow.PASSWORD;
this.username = username;