【问题标题】:salesforce lightning auth an org from another org using user agent OAuth flow and store access tokenSalesforce 使用用户代理 OAuth 流和商店访问令牌从另一个组织闪电验证一个组织
【发布时间】:2018-07-19 06:43:43
【问题描述】:
  1. 我已连接在组织 2 中创建并启用 OAuth 的应用程序。

  2. 我在 org1 中使用 OAuth2.0 用户代理工作流,我有 Lightning 应用程序。

  3. 点击闪电组件页面中的按钮(名为 auth target org)时,

  4. window.open(endpturl,'_self'); var currLoc = window.location.href; alert ('Curr Loc is: ' + currLoc); //打印我单击按钮的 URL(命名为 auth target org)。预计此语句将在第 7 步之后执行。因此无法捕获访问令牌。

  5. 重定向到 salesforce 授权/登录页面。

  6. 输入用户凭据 --> 点击允许访问。

  7. 根据连接的应用程序配置的回调 URL 重定向 https://business-momentum-162-dev-ed.cs2.my.salesforce.com/services/oauth2/success#access_token=abc&instance_url=https%3A%2F%2Fdream-innovation-4602-dev-ed.cs40.my.salesforce.com&id=https%3A%2F%2Ftest.salesforce.com%2Fid%2F00D540000009LzUEAU%2F00554000000zjC5AAI&issued_at=1531980498349&signature=abc&scope=id+api&token_type=Bearer

但我无法在第 7 步之前执行第 4 步时捕获访问令牌。因此无法捕获访问令牌。如果有办法获取/捕获访问令牌,请告诉我。

    client side controller code (**using window object**):
    ({ AuthTargetOrg : function (component, event, helper) {

    var endpturl = 'https://test.salesforce.com/services/oauth2/authorize?response_type=token&client_id=abc123&redirect_uri=https%3A%2F%2Fbusiness-momentum-162-dev-ed.lightning.force.com%2Fservices%2Foauth2%2Fsuccess';

    window.open(endpturl,'_self');
    var currLoc = window.location.href;
    alert ('Curr Loc is:  ' + currLoc); //  prints home page URL from where I clicked "auth target org" button, rather this statement expected to execute after step 7.
   )}

问候, 睡衣

【问题讨论】:

    标签: javascript oauth-2.0 salesforce-lightning


    【解决方案1】:

    我相信您需要使用 Apex 来处理 Oauth 舞蹈的重定向。我自己一直在努力解决这个问题,问题是在闪电组件中,您不能直接对销售人员端点进行 API 调用,它会引发各种错误。但是我确实找到了这个代码示例:

    https://balkishankachawa.wordpress.com/tag/oauth-with-lightning/

    基本上解决方案是使用 Apex 和 Lightning Out。使用 Apex 从 Salesforce 身份验证接收您的重定向,然后可以获取令牌并将其传递回您的闪电组件。

    【讨论】:

      猜你喜欢
      • 2018-07-07
      • 2021-10-06
      • 2020-10-08
      • 2020-05-11
      • 1970-01-01
      • 2014-04-25
      • 1970-01-01
      • 1970-01-01
      • 2013-11-05
      相关资源
      最近更新 更多