2

我使用外部服务进行身份验证 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

那么,如何捕获令牌并使用此令牌登录用户?

4

1 回答 1

0

如果我错了,请告诉我,但我认为对于 Facebook,您可以使用Torii,它与 simple-auth 配合得很好。Twitter 使用的是 Oauth1.0,所以在我看来它有点复杂。但 Facebook / Google 应该没问题。基本上,Ember 会从 Facebook API 请求一个 AuthorizationCode,然后将其发送到您的服务器。然后,您的服务器将向 Facebook API 询问 access_token,并使用它来获取用户信息。最后,您可以加载/注册您的用户,生成 JWT 令牌并将其发送到您的 Ember 应用程序。但我很想知道您是否找到了 Twitter 的解决方案。

于 2017-04-18T09:14:48.677 回答