@Override public void configureClientCredentials(Map<String, List<String>> requestParams, Map<String, String> requestHeaders) { String secret = (String) getCredentials().get("secret"); if (secret == null) { throw new RuntimeException("Client secret not provided."); } requestHeaders.put("Authorization", BasicAuthHelper.createHeader(getResource(), secret)); } };
@Override public void setClientCredentials(KeycloakDeployment deployment, Map<String, String> requestHeaders, Map<String, String> formParams) { String clientId = deployment.getResourceName(); if (!deployment.isPublicClient()) { if (clientSecret != null) { String authorization = BasicAuthHelper.createHeader(clientId, clientSecret); requestHeaders.put("Authorization", authorization); } else { logger.warnf("Client '%s' doesn't have secret available", clientId); } } else { formParams.put(OAuth2Constants.CLIENT_ID, clientId); } } }
public static AccessTokenResponse getAuthTokensBySecret(String server, String realm, String user, String password, String clientId, String secret) { StringBuilder body = new StringBuilder(); try { if (user != null) { if (password == null) { throw new RuntimeException("No password specified"); } body.append("client_id=").append(urlencode(clientId)) .append("&grant_type=password") .append("&username=").append(urlencode(user)) .append("&password=").append(urlencode(password)); } else { body.append("grant_type=client_credentials"); } InputStream result = doPost(server + "/realms/" + realm + "/protocol/openid-connect/token", APPLICATION_FORM_URL_ENCODED, APPLICATION_JSON, body.toString(), BasicAuthHelper.createHeader(clientId, secret)); return JsonSerialization.readValue(result, AccessTokenResponse.class); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unexpected error: ", e); } catch (IOException e) { throw new RuntimeException("Error receiving response: ", e); } }
public static AccessTokenResponse getAuthTokensBySecret(String server, String realm, String user, String password, String clientId, String secret) { StringBuilder body = new StringBuilder(); try { if (user != null) { if (password == null) { throw new RuntimeException("No password specified"); } body.append("client_id=").append(urlencode(clientId)) .append("&grant_type=password") .append("&username=").append(urlencode(user)) .append("&password=").append(urlencode(password)); } else { body.append("grant_type=client_credentials"); } InputStream result = doPost(server + "/realms/" + realm + "/protocol/openid-connect/token", APPLICATION_FORM_URL_ENCODED, APPLICATION_JSON, body.toString(), BasicAuthHelper.createHeader(clientId, secret)); return JsonSerialization.readValue(result, AccessTokenResponse.class); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unexpected error: ", e); } catch (IOException e) { throw new RuntimeException("Error receiving response: ", e); } }
static AccessTokenResponse getAuthTokensBySecret(String server, String realm, String user, String password, String clientId, String secret, boolean sslRequired) { StringBuilder body = new StringBuilder(); try { if (user != null) { if (password == null) { throw new RuntimeException("No password specified"); } body.append("client_id=").append(urlencode(clientId)) .append("&grant_type=password") .append("&username=").append(urlencode(user)) .append("&password=").append(urlencode(password)); } else { body.append("grant_type=client_credentials"); } setSslRequired(sslRequired); InputStream result = doPost(server + "/realms/" + realm + "/protocol/openid-connect/token", APPLICATION_FORM_URL_ENCODED, APPLICATION_JSON, body.toString(), BasicAuthHelper.createHeader(clientId, secret)); return JsonSerialization.readValue(result, AccessTokenResponse.class); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unexpected error: ", e); } catch (IOException e) { throw new RuntimeException("Error receiving response: ", e); } } }
formparams.add(new BasicNameValuePair("username", configuration.getUserName())); formparams.add(new BasicNameValuePair("password", configuration.getPassword())); String authorization = BasicAuthHelper.createHeader(configuration.getClientName(), configuration.getClientSecret()); post.setHeader("Authorization", authorization); UrlEncodedFormEntity form = new UrlEncodedFormEntity(formparams, "UTF-8");
BasicAuthHelper.createHeader( config.getServerResource(), config.getServerCredentialSecret() );
.append("&client_assertion=").append(realmConfig.getSigningToken()); } else if (realmConfig.getSecret() != null) { authorization = BasicAuthHelper.createHeader(realmConfig.getClientId(), realmConfig.getSecret());
.append("&client_assertion=").append(realmConfig.getSigningToken()); } else if (realmConfig.getSecret() != null) { authorization = BasicAuthHelper.createHeader(realmConfig.getClientId(), realmConfig.getSecret());
protected void consumeGrantTokenService(final MultivaluedMap<String, String> mvm) { boolean isPublic = config.isPublicClient(); String authorization = ""; if (isPublic) { // if client is public access type mvm.putSingle(OAuth2Constants.CLIENT_ID, config.getClientId()); } else { authorization = BasicAuthHelper.createHeader(config.getClientId(), config.getClientSecret()); } TokenService client = createTokenService(); AccessTokenResponse response = client.grantToken(config.getRealm(), authorization, mvm); int requestTime = Time.currentTime(); expirationTime = requestTime + response.getExpiresIn(); this.accessTokenResponse = response; }
protected void consumeGrantTokenService(final MultivaluedMap<String, String> mvm) { boolean isPublic = config.isPublicClient(); String authorization = ""; if (isPublic) { // if client is public access type mvm.putSingle(OAuth2Constants.CLIENT_ID, config.getClientId()); } else { authorization = BasicAuthHelper.createHeader(config.getClientId(), config.getClientSecret()); } TokenService client = createTokenService(); AccessTokenResponse response = client.grantToken(config.getRealm(), authorization, mvm); int requestTime = Time.currentTime(); expirationTime = requestTime + response.getExpiresIn(); this.accessTokenResponse = response; }