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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 174 additions and 0 deletions

View File

@ -524,6 +524,22 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
throw new RuntimeException("No OAuth2 authentication configured!"); 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. * Helper method to set the password flow for the first OAuth2 authentication.
* *

View File

@ -158,6 +158,19 @@ public class OAuth implements Authentication {
return this; 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) { public OAuth usePasswordFlow(String username, String password) {
this.flow = OAuthFlow.PASSWORD; this.flow = OAuthFlow.PASSWORD;
this.username = username; this.username = username;

View File

@ -524,6 +524,22 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
throw new RuntimeException("No OAuth2 authentication configured!"); 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. * Helper method to set the password flow for the first OAuth2 authentication.
* *

View File

@ -158,6 +158,19 @@ public class OAuth implements Authentication {
return this; 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) { public OAuth usePasswordFlow(String username, String password) {
this.flow = OAuthFlow.PASSWORD; this.flow = OAuthFlow.PASSWORD;
this.username = username; this.username = username;

View File

@ -446,6 +446,22 @@ public class ApiClient extends JavaTimeFormatter {
throw new RuntimeException("No OAuth2 authentication configured!"); 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. * 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; 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) { public OAuth usePasswordFlow(String username, String password) {
this.flow = OAuthFlow.PASSWORD; this.flow = OAuthFlow.PASSWORD;
this.username = username; this.username = username;

View File

@ -446,6 +446,22 @@ public class ApiClient extends JavaTimeFormatter {
throw new RuntimeException("No OAuth2 authentication configured!"); 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. * 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; 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) { public OAuth usePasswordFlow(String username, String password) {
this.flow = OAuthFlow.PASSWORD; this.flow = OAuthFlow.PASSWORD;
this.username = username; this.username = username;

View File

@ -530,6 +530,22 @@ public class ApiClient extends JavaTimeFormatter {
throw new RuntimeException("No OAuth2 authentication configured!"); 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. * 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; 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) { public OAuth usePasswordFlow(String username, String password) {
this.flow = OAuthFlow.PASSWORD; this.flow = OAuthFlow.PASSWORD;
this.username = username; this.username = username;

View File

@ -530,6 +530,22 @@ public class ApiClient extends JavaTimeFormatter {
throw new RuntimeException("No OAuth2 authentication configured!"); 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. * 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; 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) { public OAuth usePasswordFlow(String username, String password) {
this.flow = OAuthFlow.PASSWORD; this.flow = OAuthFlow.PASSWORD;
this.username = username; this.username = username;