2016-08-04 108 views
0

我有一个与github连接的应用程序应用程序,但身份验证流程返回授权码,而不是访问令牌,我真的不知道如何进行交换。 。至少,我在互联网上没有找到任何例子。torii获取授权码,而不是访问令牌

我有点新烬,这是我得到了什么至今

authenticator/torii.js

import Ember from 'ember'; 
import ToriiAuthenticator from 'ember-simple-auth/authenticators/torii'; 

export default ToriiAuthenticator.extend({ 
    torii: Ember.inject.service() 
}); 

torii-providers/github.js

import GithubOauth2Provider from 'torii/providers/github-oauth2'; 

export default GithubOauth2Provider.extend({ 
    fetch(data) { 
    return data; 
    } 
}); 

我知道我可能要改变的东西的供应商,但我真的不知道从哪里开始

回答

3

我已经使用Torii做GitHub认证自己。这里是我的建议:

  1. Drop ember-simple-auth并直接使用Torii。讽刺的是,ember-simple-auth的Torii包装并不“简单”。
  2. 您应该翻阅Torii's docs以熟悉图书馆。
  3. 在您的config/environment.js中,配置Torii。例如:

    torii: { 
        sessionServiceName: 'session', 
        providers: { 
        'github-oauth2': { 
         // your api key goes here 
         apiKey: '', 
    
         // link to your app goes here 
         // in development mode, it should be http://localhost:4200 
         redirectUri: '', 
    
         // specify OAuth scope here 
         scope: '' 
        } 
        } 
    } 
    
  4. 创建一个名为torii-adapters/application.js文件。在这里您需要实施三种方法.open(),.fetch().close()。请注意,您将收到authorizationCode作为.open()的参数,您应该与访问令牌交换(使用您的身份验证后端)。

  5. 哦,你需要一个OAuth后端,保持你的客户端私密。您将授权代码从您的Ember应用程序发送到您的OAuth后端,OAuth后端使用访问令牌进行响应。

如果这对您没有任何意义,请查看this blog post,其中有一个很好的OAuth摘要。您应该了解大局,以便填写细节非常简单。 :)

+0

很酷,我会试一试!非常感谢,杰森 –

+0

https://madhatted.com/2014/06/17/authentication-for-single-page-apps新的博客文章链接 – outsmartin