【问题标题】:How can i encrypt my oauth post request for salesforce withut using signpost,scribe type library如何在不使用 signpost、scribe 类型库的情况下加密我的 oauth post 请求给 salesforce
【发布时间】: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


    【解决方案1】:

    我认为您混淆了协议。 OAuth 2 不使用签名。 (OAuth1 可以)。

    授权请求通常需要response_type、client_id、redirect_uri 和state。 (还有其他参数,例如 scope,但并非总是如此)。

    使用 response_type=code 时,您会从授权服务器(例如 Salesforce、Google)获得 code。然后使用/token 端点将代码交换为令牌。该端点使用client_secret。

    (此处描述了该协议的概述:https://auth0.com/docs/protocols#1)

    【讨论】:

    • 这一切我都知道。我不是在谈论 oauth_signature 作为 oauth 1.0 中的参数。我在问如何在发送之前将整个帖子请求签署到 salesforce 端点 url。目前,任何人都可以在 saml 跟踪器中将客户端机密视为纯文本作为 post 参数。
    • 您可能想改写/重写您的问题。不是很清楚你想做什么。在任何情况下,签名都不会阻止秘密的可见性。你可能想加密它。此外,client _secrets 永远不会从用户代理发送。它们用于服务器端调用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-02
    • 2015-01-20
    • 2013-01-14
    相关资源
    最近更新 更多