【发布时间】: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