【问题标题】:Use state in Auth0 rule在 Auth0 规则中使用状态
【发布时间】:2018-07-03 06:10:38
【问题描述】:

我想将自定义标识符传递到 Auth0 授权端点。该值是在我们的数据库中标识用户的 guid。

我在 Auth0.js 授权函数的 state 参数中传递它。

    this.auth0.authorize({
        initial_screen: 'signUp',
        lead_guid: leadGuid,
        state: leadGuid
    });

我可以在规则中看到state 的值,但它是经过编码的。文档表明它是 base64,但它不解码。

在规则之前,在托管登录页面中,如果我抓取配置,我会得到这些值:

  "extraParams": {
    "initial_screen": "signUp",
    "lead_guid": "33071cf4-17c4-44fe-b573-fc86dfa7e413",
    "state": "ll8tw5lkrSELOf1cnTygwBlewWrRK_Zo"
  },
  "internalOptions": {
    "initial_screen": "signUp",
    "lead_guid": "33071cf4-17c4-44fe-b573-fc86dfa7e413",
    "state": "ll8tw5lkrSELOf1cnTygwBlewWrRK_Zo",
  },

lead_guid 正在传递到 extraParamsinternalOptions,但尚未设置状态值。

如果我将传递给 Lock 的对象中的值设置为 Auth 参数:

if (leadGuid) {
  config.extraParams.state = leadGuid;
  config.internalOptions.state = leadGuid;
}

var lock = new Auth0Lock(config.clientID, config.auth0Domain, {
  auth: {
    redirectUrl: config.callbackURL,
    responseType: (config.internalOptions || {}).response_type ||
      config.callbackOnLocationHash ? 'token' : 'code',
    params: config.internalOptions
  },

当我尝试注册时,我收到此错误:

您可能按下了返回按钮,在登录时刷新,打开 登录对话框太多,或者 cookie 有问题,因为我们 找不到您的会话。尝试从应用程序再次登录 如果问题仍然存在,请联系管理员。

如果我用自定义状态初始化 auto0.WebAuth:

auth0 = new auth0.WebAuth({
    clientID: environment.auth0.clientId,
    domain: environment.auth0.domain,
    responseType: 'token id_token',
    audience: environment.auth0.audience,
    redirectUri: environment.auth0.interactiveRedirectUri,
    scope: 'openid profile email',
    state: 'anthony'
});

然后获取AuthResult状态,就可以看到我的自定义值了。规则记录的值似乎是内部 Auth0 状态。

Auth0 规则是否有可能以明文形式获取 state 的值,以便将其传递给 webhook?

【问题讨论】:

  • 您能否将规则中的相关代码粘贴到问题中?

标签: auth0


【解决方案1】:

将调用改为

this.auth0.authorize({
    initial_screen: 'signUp',
    lead_guid: leadGuid,
});

lead_guid 可在使用 context.request.query.lead_guid 的 Auth0 规则中使用

【讨论】:

    猜你喜欢
    • 2018-02-15
    • 1970-01-01
    • 2017-09-22
    • 2021-11-03
    • 2017-05-25
    • 2020-06-29
    • 2015-06-05
    • 1970-01-01
    • 2021-08-08
    相关资源
    最近更新 更多