简体   繁体   English

使用令牌回调后,使用外部网址,Ember简单身份验证对用户进行身份验证

[英]Authenticate user with external url, Ember Simple Auth after callback with token

I use an external service for authentication Stamplay .. 我使用外部服务来认证Stamplay ..

To authenticate with username and password, I have to make a post in ${config.host}/auth/v1/local/login The callback for this post contain the token, so I created a custom authenticator to handle it 要使用用户名和密码进行身份验证,我必须在${config.host}/auth/v1/local/login发布此帖子的回调包含令牌,因此我创建了一个自定义身份验证器来处理它

Custom Authenticator 定制验证器

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);
  }
});

And everything works fine.. but ... 而且一切正常..但是...

My problem 我的问题

For social logins, I need to redirect the user to https://MYAPP.stamplayapp.com/auth/v1/EXTERNAL_SERVICE/connect 对于社交登录,我需要将用户重定向到https://MYAPP.stamplayapp.com/auth/v1/EXTERNAL_SERVICE/connect

EXTERNAL_SERVICE can be.. github, twitter, facebook... EXTERNAL_SERVICE可以是.. github,twitter,facebook ...

Then, the user is redirect to service page, and after login, the callback will be http://myapp.com/callback?jwt=XYZ 然后,将用户重定向到服务页面,并且在登录后,回调将为http://myapp.com/callback?jwt=XYZ

So, how can I capture the token and login the user with this token? 那么,如何捕获令牌并使用此令牌登录用户?

Tell me if I'm wrong, but I think that for Facebook you can use Torii which is working well with simple-auth. 告诉我是否错,但是我认为对于Facebook,您可以使用Torii ,它与simple-auth配合良好。 Twitter is using Oauth1.0, so it's a bit more complicated in my opinion. Twitter使用的是Oauth1.0,因此我认为它有点复杂。 But Facebook / Google should be fine. 但是Facebook / Google应该没问题。 Basically, Ember will request an AuthorizationCode from Facebook API, then send it to your server. 基本上,Ember将从Facebook API请求一个AuthorizationCode,然后将其发送到您的服务器。 Your server will then ask Facebook API an access_token, and use it to get the user information. 然后,您的服务器将询问Facebook API一个access_token,并使用它来获取用户信息。 Finally, you can load/register your user, generate a JWT token and send it to your Ember app. 最后,您可以加载/注册用户,生成JWT令牌并将其发送到Ember应用。 But I'm interested to know if you have found a solution for Twitter. 但是我很想知道您是否找到了Twitter的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM