我使用外部服务进行身份验证 Stamplay ..
要使用用户名和密码进行身份验证,我必须在${config.host}/auth/v1/local/login
此帖子的回调中发一个帖子包含令牌,因此我创建了一个自定义身份验证器来处理它
自定义身份验证器
export default Base.extend({
tokenEndpoint: `${config.host}/auth/v1/local/login`,
// ... Omited
authenticate(options) {
return new Ember.RSVP.Promise((resolve, reject) => {
Ember.$.ajax({
url: this.tokenEndpoint,
type: 'POST',
data: JSON.stringify({
email: options.email,
password: options.password
}),
contentType: 'application/json;charset=utf-8',
dataType: 'json'
}).then(function (response, status, xhr) {
Ember.run(function () {
resolve({
token: xhr.getResponseHeader('x-stamplay-jwt')
});
});
}, function (xhr) {
Ember.run(function () {
reject(xhr.responseJSON.error);
});
});
});
},
invalidate(data) {
return Ember.RSVP.Promise.resolve(data);
}
});
一切正常……但是……
我的问题
对于社交登录,我需要将用户重定向到https://MYAPP.stamplayapp.com/auth/v1/EXTERNAL_SERVICE/connect
EXTERNAL_SERVICE可以是.. github、twitter、facebook...
然后,用户被重定向到服务页面,登录后,回调将是http://myapp.com/callback?jwt=XYZ
那么,如何捕获令牌并使用此令牌登录用户?