Skip to content

Commit

Permalink
Minor code improvements
Browse files Browse the repository at this point in the history
Signed-off-by: David Kral <[email protected]>
  • Loading branch information
Verdent committed Dec 15, 2023
1 parent 4860a67 commit 77a3c37
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;

import io.helidon.common.Errors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private AuthenticationResponse errorResponse(ProviderRequest providerRequest,
StringBuilder scopes = new StringBuilder(tenantConfig.baseScopes());

for (String expectedScope : expectedScopes) {
if (scopes.length() > 0) {
if (!scopes.isEmpty()) {
// space after base scopes
scopes.append(' ');
}
Expand All @@ -355,14 +355,12 @@ private AuthenticationResponse errorResponse(ProviderRequest providerRequest,
+ encode(oidcConfig.tenantParamName()) + "=" + encode(tenantId));
}


StringBuilder queryString = new StringBuilder("?");
queryString.append("client_id=").append(tenantConfig.clientId()).append("&");
queryString.append("response_type=code&");
queryString.append("redirect_uri=").append(redirectUri).append("&");
queryString.append("scope=").append(scopeString).append("&");
queryString.append("nonce=").append(nonce).append("&");
queryString.append("state=").append(encode(state));
String queryString = "?" + "client_id=" + tenantConfig.clientId() + "&"
+ "response_type=code&"
+ "redirect_uri=" + redirectUri + "&"
+ "scope=" + scopeString + "&"
+ "nonce=" + nonce + "&"
+ "state=" + encode(state);

// must redirect
return AuthenticationResponse
Expand All @@ -380,7 +378,7 @@ private AuthenticationResponse errorResponse(ProviderRequest providerRequest,
private String redirectUri(SecurityEnvironment env) {
for (Map.Entry<String, List<String>> entry : env.headers().entrySet()) {
if (entry.getKey().equalsIgnoreCase("host") && !entry.getValue().isEmpty()) {
String firstHost = entry.getValue().get(0);
String firstHost = entry.getValue().getFirst();
return oidcConfig.redirectUriWithHost(oidcConfig.forceHttpsRedirects() ? "https" : env.transport()
+ "://" + firstHost);
}
Expand Down Expand Up @@ -452,7 +450,7 @@ private String origUri(ProviderRequest providerRequest) {
origUri = List.of(providerRequest.env().targetUri().getPath());
}

return origUri.get(0);
return origUri.getFirst();
}

private String encode(String state) {
Expand Down

0 comments on commit 77a3c37

Please sign in to comment.