Ember Simple Auth Torri自定义提供商

时间:2015-07-27 03:12:45

标签: ember.js oauth-2.0 ember-cli yahoo-api ember-simple-auth

我正在尝试为Yahoo OAuth 2.0为Ember Simple Auth Torri包装器创建自定义OAuth提供程序。 我使用内置的Facebook和Google提供商没有任何问题,但由于默认情况下不提供Yahoo OAuth包,我试图按照手册创建我自己的。

\b #Start at the beginning of a word.

(?!(are|to|a|the|at|in|of|with|and|but|or)   #match only if a word does not begin with "to, a, the, at, in, of, with, and, but, or"

\b #Second \b to signify that there are no characters after the words listed in the negative lookahead list.

\w  #Match any single word character

$letter.Value.ToUpper()  # convert the matched letter(value) to uppercase

在我的控制器中,我将其称为 -

//app/torri-provider/yahoo-oauth2.js

export default Ember.Object.extend({
  host: 'https://api.login.yahoo.com/oauth2/',
  // create a new authorization
  open: function(options) {
    return new Ember.RSVP.Promise(function(resolve, reject){
      console.log("Hi");
      var authurl="https://api.login.yahoo.com/oauth2/request_auth";

      return $.ajax(authurl, "GET", {
        // CORS
        crossDomain: true,
        xhrFields: {withCredentials: true}
      }).then(function(json) {
        // Massage this demo API endpoint to look like RESTAdapter expects.
        return { things: [json] };
      });


    });
  }
});

然而,我无法参与CORS问题并在我的控制台上收到以下错误 -

  

userhomeinvitemembers:1 XMLHttpRequest无法加载   https://api.login.yahoo.com/oauth2/request_auth。没有   '访问控制允许来源'标题出现在请求的上   资源。起源' http://localhost:4200'因此是不允许的   访问。

我尝试将oauth2端点添加到ember cli白名单和内容安全策略白名单,但仍然会出现相同的错误。

'yahoo-share':function(){
  var self=this;
  this.get('session').authenticate('simple-auth-authenticator:torii',"yahoo-oauth2");
},

1 个答案:

答案 0 :(得分:0)

我认为您不能通过AJAX调用它,但需要打开弹出窗口,以允许用户输入他们的Yahoo凭据并授权您的应用程序。完成后,Yahoo将重定向到您定义的路由,并在查询字符串中包含一个auth代码,然后torii将读取并回发到父窗口(请参阅默认OAuth 2.0提供程序的源{'{1}}方法:https://github.com/Vestorly/torii/blob/master/lib/torii/providers/oauth2-code.js#L118)。

相关问题