简体   繁体   English

torii获取授权码而不是访问令牌

[英]torii gets authorization code instead access token

I have an ember app that connects with github, but the authentication flow returns the authorization code , not the access token, and I don't really know how to do the exchange...well, at least I didn't found any examples on the internet. 我有一个与github连接的ember应用程序,但是身份验证流程返回的是授权码 ,而不是访问令牌,而且我真的不知道如何进行交换...嗯,至少我没有找到任何示例在网上。

I'm kinda new to ember, this is what I got so far 我是炭烬的新手,这是我到目前为止得到的

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

I know I may have to change something in the provider, but I don't really know where to start 我知道我可能需要更改提供程序中的某些内容,但我真的不知道从哪里开始

I've used Torii to do GitHub auth myself. 我曾经使用Torii自己进行GitHub身份验证。 Here's my advice: 这是我的建议:

  1. Drop ember-simple-auth and just use Torii directly. 删除ember-simple-auth,直接使用Torii。 Ironically, ember-simple-auth's Torii wrapper isn't "simple". 具有讽刺意味的是,ember-simple-auth的Torii包装器不是“简单的”。
  2. You should go over Torii's docs to familiarize yourself with the library. 您应该阅读Torii的文档以熟悉该库。
  3. In your config/environment.js , configure Torii. 在您的config/environment.js ,配置Torii。 Example: 例:

     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. Create a file called torii-adapters/application.js . 创建一个名为torii-adapters/application.js的文件。 Here you will need to implement the three methods .open() , .fetch() , and .close() . 在这里,您将需要实现.open() .fetch().close()的三种方法。 Note that you will receive the authorizationCode as a parameter for .open() , which you should exchange (with your auth backend) for an access token. 请注意,您将收到authorizationCode作为.open()的参数, .open()其与访问令牌交换(与auth后端)。

  5. Oh, and you'll need an OAuth backend that keeps your client secret private. 哦,您将需要一个OAuth后端,以将您的客户端秘密保密。 You send the authorization code from your Ember app to your OAuth backend, and the OAuth backend responds with an access token. 您将授权代码从Ember应用发送到OAuth后端,OAuth后端将以访问令牌进行响应。

If none of that made any sense to you, check out this blog post , which has a good summary of OAuth. 如果对您没有任何意义,请查看此博客文章 ,其中对OAuth进行了很好的总结。 You should understand the big picture so that filling in the details is easy. 您应该了解全局,以便轻松填写细节。 :) :)

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

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