【问题标题】:Never expire Salesforce session永不过期 Salesforce 会话
【发布时间】:2019-01-10 02:24:17
【问题描述】:

我在我的应用程序中集成Salesforce OAuth。在将用户的Salesforce 帐户与我们的应用程序帐户映射后,我将访问令牌保存在数据库中。当用户请求从他的 Salesforce 帐户中获取数据时,我只是使用该令牌来获取数据。遗憾的是,令牌有过期时间(最多 24 小时)。令牌过期后,用户必须再次将 salesforce 帐户与我们的应用程序连接。

是否有办法让 salesforce 会话无限期保持活动状态,或者以任何其他方式避免重复登录?

【问题讨论】:

    标签: asp.net oauth salesforce


    【解决方案1】:

    我认为您正在寻找的是刷新令牌过程。虽然您可以控制到期时间,但正如您所说,您无法通过某些限制。相反,您可以向您的组织发送可以为您获取新会话 ID 的请求。

    例子:

    POST /services/oauth2/token HTTP/1.1
    Host: https://login.salesforce.com/ 
    grant_type=refresh_token&client_id=3MVG9lKcPoNINVBIPJjdw1J9LLM82HnFVVX19KY1uA5mu0
    QqEWhqKpoW3svG3XHrXDiCQjK1mdgAvhCscA9GE&client_secret=1955279925675241571
    &refresh_token=***your token here*** 
    

    请注意,如果您使用的是用户名密码 OAuth 身份验证流程,这将不起作用。查看此开发文档以了解可用于刷新令牌的参数以及它可以返回的响应。 - https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_refresh_token_oauth.htm

    【讨论】:

      【解决方案2】:

      无法确保用户会话永不过期。但是,您可以将会话超时值设置为最长 24 小时。

      【讨论】:

        【解决方案3】:

        我同意 Iojo。我实现了将令牌保存在数据库中的类似要求,并将其用于多个 API 标注。

        注意:就我而言 - 对于所有 API 标注 - 身份验证层由相同的中间件负责。此外,我使用用户名密码作为访问令牌,显然我不能使用刷新令牌。

        我用令牌为 Access Token 做了什么 保存在数据库中?

        //Please create a re-usable method in the Rest handler to Retrieve Token
        private string getToken(){
            If(Token created within Session Timeout Limit){
              //Use encrypted token given in the DB 
            }
            else{
             //reuse code to generate new token 
             //save the encrypted token in the DB for future use
            }
        }
        

        好处:

        1. 您只需在给定的会话超时限制内生成一次令牌
        2. 如果 salesforce 中有多个 API 调用,则重复使用相同的方法

        【讨论】:

          猜你喜欢
          • 2013-09-19
          • 1970-01-01
          • 2013-11-23
          • 1970-01-01
          • 1970-01-01
          • 2013-10-26
          • 2012-07-06
          • 1970-01-01
          • 2015-05-28
          相关资源
          最近更新 更多