Skip to content

Commit

Permalink
Java jersey OAuth2 add support for public client #13827 (#13828)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbilz authored Oct 31, 2022
1 parent a04b262 commit fe5601a
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,22 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,22 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,22 @@ public ApiClient setOauthCredentials(String clientId, String clientSecret) {
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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ public OAuth setCredentials(String clientId, String clientSecret, Boolean debug)
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,22 @@ public ApiClient setOauthCredentials(String clientId, String clientSecret) {
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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ public OAuth setCredentials(String clientId, String clientSecret, Boolean debug)
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,22 @@ public ApiClient setOauthCredentials(String clientId, String clientSecret) {
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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ public OAuth setCredentials(String clientId, String clientSecret, Boolean debug)
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,22 @@ public ApiClient setOauthCredentials(String clientId, String clientSecret) {
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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ public OAuth setCredentials(String clientId, String clientSecret, Boolean debug)
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;
Expand Down

0 comments on commit fe5601a

Please sign in to comment.