我创建了一个干净的 ember 应用程序,安装了 simple-auth 并为 facebook 实现了一个自定义身份验证器。
https://github.com/prule/ember-auth-spike
我可以看到我已成功从 FB 获取访问令牌并将其放入会话中(通过 chrome ember 扩展检查容器会话显示会话已通过身份验证并且访问令牌可见)。
但是当我在浏览器中重新加载页面时,会话状态会丢失。这是预期的行为吗?我在自定义身份验证器中做错了吗?验证器代码是来自https://github.com/simplabs/ember-simple-auth/blob/master/examples/7-multiple-external-providers.html的直接复制和粘贴(加上一些 console.logs)
谢谢,我很感激任何帮助。
import Ember from 'ember';
import Base from 'simple-auth/authenticators/base';
export default Base.extend({
restore: function (data) {
return new Ember.RSVP.Promise(function (resolve, reject) {
console.log('restore');
if (!Ember.isEmpty(properties.accessToken)) {
console.log('found access token '+properties.accessToken);
resolve(properties);
}
else {
console.log('no token found');
reject();
}
});
},
authenticate: function (options) {
return new Ember.RSVP.Promise(function (resolve, reject) {
console.log('1');
FB.getLoginStatus(function (fbResponse) {
console.log('2');
console.log(fbResponse);
if (fbResponse.status === 'connected') {
Ember.run(function () {
console.log(fbResponse.authResponse.accessToken);
resolve({accessToken: fbResponse.authResponse.accessToken});
});
}
else if (fbResponse.status === 'not_authorized') {
reject();
}
else {
FB.login(function (fbResponse) {
if (fbResponse.authResponse) {
Ember.run(function () {
console.log(fbResponse.authResponse.accessToken);
resolve({accessToken: fbResponse.authResponse.accessToken});
});
}
else {
reject();
}
});
}
});
});
},
invalidate: function (data) {
return new Ember.RSVP.Promise(function (resolve, reject) {
FB.logout(function (response) {
Ember.run(resolve);
});
});
}
});