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.
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. Here's my advice:
In your config/environment.js
, configure 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: ''
}
}
}
Create a file called torii-adapters/application.js
. Here you will need to implement the three methods .open()
, .fetch()
, and .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.
If none of that made any sense to you, check out this blog post, which has a good summary of OAuth. You should understand the big picture so that filling in the details is easy. :)