【问题标题】:Ember-simple-auth does not persist refresh'sEmber-simple-auth 不会持续刷新
【发布时间】:2015-12-16 22:49:39
【问题描述】:

我很沮丧,我不明白为什么 ember-simple-auth 页面刷新时不会持续存在...我正在返回 access_token 并按照文档实现 oauth2 ....

这是我的代码:

身份验证器/oauth2.js:

import OAuth2PasswordGrant from 'ember-simple-auth/authenticators/oauth2-password-grant';

export default OAuth2PasswordGrant.extend({
  serverTokenEndpoint: 'http://localhost:3000/users/compare'
});

授权者/oauth2.js:

import OAuth2Bearer from 'ember-simple-auth/authorizers/oauth2-bearer';

export default OAuth2Bearer.extend();

适配器/application.js:

import DS from 'ember-data';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';

const {
  JSONAPIAdapter
} = DS;

export default JSONAPIAdapter.extend(DataAdapterMixin, {
  authorizer: 'authorizer:oauth2',
  host: 'http://localhost:3000'
});

我将返回 access_token 和用户名。我可以看到经过身份验证的路由,但如果我刷新页面,会话将会丢失。

在我经过身份验证的对象中:

access_token: "token"
username: "myUserName"

在我的安全对象中,我有:

authenticator: "simple-auth-authenticator:jwt"
access_token "token"
username: "myUserName"

我不明白为什么这个验证器..我正在使用它但我已经删除了所有相关的内容。

在我的 localStorage 我有:

{"secure":{"authenticator":"simple-auth-authenticator:jwt","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6Im1hcmNlbG9AcHViY3Jhd2xzcC5jb20iLCJpYXQiOjE0NDk1OTY5NDV9.fP11KL2as2mI7ocFojS-H3jUW60XgWCUskTNi4iy1XY","name":"Fatima Alves"},"authenticated":{"authenticator":"authenticator:oauth2","access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6Im1hcmNlbG9AcHViY3Jhd2xzcC5jb20iLCJpYXQiOjE0NTAzMDU3MDN9.GKb5A15BBXxgcO9SDrGnxv0CQvkhXQCqvrK65MQ2ROc","name":"Fatima Alves"}}

【问题讨论】:

    标签: javascript authentication ember.js ember-simple-auth


    【解决方案1】:

    您在安全数据中缺少一些属性,这些属性是 OAuth2PasswordGrantAuthenticator 正确恢复所必需的。

    Check out the restore() implementation here.

    【讨论】:

    • 好的,我终于可以让它工作了,但是因为这个“Bearer”,我无法在每个请求中验证我的令牌。我应该把这个从usando切片上取下来吗??
    • 我不确定您使用的是什么服务器端,但如果您自己进行身份验证,请随时将其剥离。它只是用来指示它是什么类型的令牌。
    • 我只使用 JWT 和 bcrypt @uberclops。
    • 我在项目中使用相同的,所以在验证令牌之前,只需从服务器上的身份验证层的 Authorization 标头中删除 Bearer
    • JWT 在这方面可能会有所帮助。
    猜你喜欢
    • 2019-09-04
    • 1970-01-01
    • 2018-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多