【问题标题】:Ember Simple Auth immediately invalidates the session after authenticating with Torii在使用 Torii 进行身份验证后,Ember Simple Auth 立即使会话无效
【发布时间】:2016-03-03 22:23:30
【问题描述】:

我正在尝试使用我自己的 OAuth 流程和 Ember-Simple-Auth 设置 Torii。我可以获得一个成功的身份验证事件,但在我进行身份验证后,invalidateSession 触发器被触发,导致我的会话结束。我可以通过在/app/routes/application.js(有ApplicationRouteMixin)中截获sessionInvalidated() 来看到这一点。

你们中有人遇到过这种情况吗?是否有一些特殊的东西会导致立即进行会话验证?任何建议将不胜感激。

编辑:我认为这与 torii 弹出代码有关,因为第一个返回有效,但第二个无效。有什么想法吗?

import OAuth2 from 'torii/providers/oauth2-code';
import {configurable} from 'torii/configuration';

export default OAuth2.extend({
  name: 'api',
  init() { this.set('clientID', this.get('apiKey')); },

  baseUrl: configurable('baseUrl'),

  redirectUri: configurable('redirectUri'),
  responseParams: ['access_token', 'user_id', 'first_name'],

  requiredUrlParams: ['client_id', 'redirect_uri', 'response_type'],

  open() {
    let name        = this.get('name');
    let url         = this.buildUrl();
    let redirectUri = this.get('redirectUri');
    let responseParams = this.get('responseParams');

    // this return works
    return { 'yes' : 'no' }

    // this return causes the immediate invalidation
    return this.get('popup').open(url, responseParams).then((authData) => {
      var missingResponseParams = [];

      responseParams.forEach(function(param){
        if (authData[param] === undefined) {
          missingResponseParams.push(param);
        }
      });

      if (missingResponseParams.length){
        throw new Error("The response from the provider is missing " +
              "these required response params: " + missingResponseParams.join(', '));
      }

      return {
        access_token: authData.access_token,
        first_name: authData.first_name,
        user_id: authData.user_id,
        provider: name,
        redirectUri: redirectUri
      };
    });
  }
});

【问题讨论】:

  • 我在 FWIW 遇到了完全相同的问题。我在 ApplicationRouteMixin 的 sessionAuthenticated 和 sessionInvalidated 挂钩中添加了 debugger 语句。身份验证后,我点击了第一个调试器语句并在 localStorage 中看到了身份验证凭据,然后我点击了第二个调试器语句并且身份验证凭据消失了。
  • @danpaz 看看这个:github.com/simplabs/ember-simple-auth/pull/931。这个分支对我有用,希望它也对你有用。
  • 为我工作,谢谢!

标签: ember.js ember-simple-auth torii


【解决方案1】:

真正的答案是使用这个 fork:https://github.com/simplabs/ember-simple-auth/pull/931(希望它很快就会成为 master)。

【讨论】:

    【解决方案2】:

    您可能在某处拥有this.get('session').invalidate();。可能在您的控制器操作属性之一中。您通常会将其放在注销按钮的操作中。也许您不小心复制并粘贴了它。如果您发布一些代码,我也许可以再看一下它

    【讨论】:

    • 感谢您的回答,不幸的是不是这样。我用更多代码编辑了我的问题。我认为这与 torii 弹出窗口有关。
    猜你喜欢
    • 2020-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-24
    • 2017-07-15
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多