private String getAuthorizationBody(final OAuth2Accessor accessor) throws OAuth2RequestException { String ret = ""; final Map<String, String> queryParams = Maps.newHashMap(); queryParams.put(OAuth2Message.GRANT_TYPE, this.getGrantType()); final String clientId = accessor.getClientId(); final byte[] secretBytes = accessor.getClientSecret(); String secret; try { secret = new String(secretBytes, "UTF-8"); } catch (final UnsupportedEncodingException e) { throw new OAuth2RequestException(OAuth2Error.CLIENT_CREDENTIALS_PROBLEM, "error getting authorization body", e); } queryParams.put(OAuth2Message.CLIENT_ID, clientId); queryParams.put(OAuth2Message.CLIENT_SECRET, secret); ret = OAuth2Utils.buildUrl(ret, queryParams, null); final char firstChar = ret.charAt(0); if (firstChar == '?' || firstChar == '&') { ret = ret.substring(1); } return ret; }
final byte[] secretBytes = accessor.getClientSecret(); final String secret = new String(secretBytes, "UTF-8"); queryParams.put(OAuth2Message.CLIENT_ID, clientId);
final byte[] secret = accessor.getClientSecret(); queryParams.put(OAuth2Message.CLIENT_ID, clientId); queryParams.put(OAuth2Message.CLIENT_SECRET, new String(secret, "UTF-8"));
public OAuth2HandlerError addOAuth2Authentication(final HttpRequest request, final OAuth2Accessor accessor) { try { if (request == null) { return BasicAuthenticationHandler.getError("request is null"); } if (accessor == null || !accessor.isValid() || accessor.isErrorResponse()) { return BasicAuthenticationHandler.getError("accessor is invalid " + accessor); } final String clientId = accessor.getClientId(); if (clientId == null) { return BasicAuthenticationHandler.getError("client_id is null"); } final byte[] secretBytes = accessor.getClientSecret(); if (secretBytes == null) { return BasicAuthenticationHandler.getError("client_secret is secret"); } final String secret = new String(secretBytes, "UTF-8"); final String authString = clientId + ':' + secret; final byte[] authBytes = Base64.encodeBase64(authString.getBytes()); request.setHeader(OAuth2Message.AUTHORIZATION_HEADER, "Basic: " + new String(authBytes)); return null; } catch (final Exception e) { return BasicAuthenticationHandler.getError("Exception adding basic auth headers", e); } }
final byte[] secretBytes = accessor.getClientSecret(); final String secret = new String(secretBytes, "UTF-8"); queryParams.put(OAuth2Message.CLIENT_ID, clientId);
public OAuth2HandlerError addOAuth2Authentication(final HttpRequest request, final OAuth2Accessor accessor) { try { if (request == null) { return StandardAuthenticationHandler.getError("request is null"); } if (accessor == null) { return StandardAuthenticationHandler.getError("accessor is null"); } if (!accessor.isValid() || accessor.isErrorResponse()) { return StandardAuthenticationHandler.getError("accessor is invalid"); } final String clientId = accessor.getClientId(); if (clientId == null) { return StandardAuthenticationHandler.getError("client_id is null"); } final byte[] secretBytes = accessor.getClientSecret(); if (secretBytes == null) { return StandardAuthenticationHandler.getError("client_secret is secret"); } final String secret = new String(secretBytes, "UTF-8"); request.setHeader(OAuth2Message.CLIENT_ID, clientId); request.setParam(OAuth2Message.CLIENT_ID, clientId); request.setHeader(OAuth2Message.CLIENT_SECRET, secret); request.setParam(OAuth2Message.CLIENT_SECRET, secret); return null; } catch (final Exception e) { return StandardAuthenticationHandler.getError("Exception adding standard auth headers", e); } }
this.urlParameter = accessor.isUrlParameter(); this.clientId = accessor.getClientId(); this.clientSecret = accessor.getClientSecret(); this.gadgetUri = accessor.getGadgetUri(); this.grantType = accessor.getGrantType();