Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
fixup! fixup! fixup! fixup! rh-che #541: Login to user project using …
Browse files Browse the repository at this point in the history
…oc CLI in workspace containers
  • Loading branch information
Oleksandr Garagatyi committed Mar 5, 2018
1 parent e26e2b8 commit 7258d00
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class OpenshiftUserTokenProvider {
private final LoadingCache<String, String> tokenCache;

@Inject
public OpenshiftUserTokenProvider(@Named("che.fabric8.auth.endpoint") String authEndpoint,
OkHttpClient httpClient) {
public OpenshiftUserTokenProvider(
@Named("che.fabric8.auth.endpoint") String authEndpoint, OkHttpClient httpClient) {
this.tokenEndpoint = authEndpoint + "/api/token?for=openshift";
this.httpClient = httpClient;
this.tokenCache =
Expand All @@ -60,7 +60,7 @@ public OpenshiftUserTokenProvider(@Named("che.fabric8.auth.endpoint") String aut
* @param subject subject with user's keycloak token
* @return Openshift user token
* @throws InfrastructureException when there is no keycloak token in subject or OSO token
* retrieval failed
* retrieval failed
*/
public String getToken(Subject subject) throws InfrastructureException {
checkSubject(subject);
Expand Down Expand Up @@ -97,8 +97,11 @@ private String getUserDescription(Subject subject) {

private String getOsToken(final String keycloakToken) throws RuntimeException {
Request request =
new Request.Builder().url(tokenEndpoint).get()
.header("Authorization", "Bearer " + keycloakToken).build();
new Request.Builder()
.url(tokenEndpoint)
.get()
.header("Authorization", "Bearer " + keycloakToken)
.build();
try {
Response response = httpClient.newCall(request).execute();
// Ignore IDE warning:
Expand All @@ -111,11 +114,7 @@ private String getOsToken(final String keycloakToken) throws RuntimeException {
"Could not retrieve OSO token of the user. Response from auth service: " + body);
}

return new JsonParser()
.parse(body)
.getAsJsonObject()
.get("access_token")
.getAsString();
return new JsonParser().parse(body).getAsJsonObject().get("access_token").getAsString();
} catch (IOException e) {
throw new RuntimeException(
"Could not retrieve OSO token from of the user. Error: " + e.getMessage());
Expand Down

0 comments on commit 7258d00

Please sign in to comment.