【发布时间】:2015-05-31 18:57:52
【问题描述】:
我想要用于加密我的 oauth 2.0 发布请求的示例基本代码,这些代码将适用于 google、salesforce 等多个应用程序。
我已经尝试使用此代码进行 Salesforce 授权,但它给了我错误的请求错误。我试图签署 oauth 发布请求,但在 oauth 1.0 和 2.0 中感到困惑 -
public String getAuthorizationUrl() {
LOGGER.debug("SalesforceUtility - getAuthorizationUrl");
try {
String baseUrl = "?response_type=code" + "&client_id="
+ this.clientSecrets.get("client_id") + "&redirect_uri="+ URLEncoder.encode(this.clientSecrets.getString("redirect_uri"), "UTF-8");
String authorize_url = this.clientSecrets.get("auth_uri")
+ baseUrl ;
computeSignature(baseUrl,client_secret);
LOGGER.debug("SalesforceUtility - AuthorizationUrl" + authorize_url);
return authorize_url;
} catch (Exception e) {
LOGGER.error("Exception getAuthorizationUrl", e);
throw new BusinessException(e,
BusinessErrorCode.SALESFORCE_AUTH_URL);
}
}
private static String computeSignature(String baseString, String keyString) {
SecretKey secretKey = null;
byte[] keyBytes = keyString.getBytes();
secretKey = new SecretKeySpec(keyBytes, "HmacSHA1");
Mac mac;
try {
mac = Mac.getInstance("HmacSHA1");
mac.init(secretKey);
byte[] text = baseString.getBytes();
return new String(Base64.encodeBase64(mac.doFinal(text))).trim();
} catch (Throwable t) {
throw new SystemException(SystemErrorCode.SALESFORCE_UNSUPPORTED_ENCODING_EXCEPTION);
}
}
【问题讨论】:
标签: oauth oauth-2.0 salesforce authorization google-oauth