Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How get access_token? #203

Open
paulocastellano opened this issue Mar 22, 2020 · 3 comments
Open

How get access_token? #203

paulocastellano opened this issue Mar 22, 2020 · 3 comments

Comments

@paulocastellano
Copy link

Hello I need to get access_token in place of the "code".

Any ideas how I can get it?

@SahilVasava
Copy link

If you want token for google then, in config along with URL, clientId, etc. pass responseType: "token"

@manuelgeek
Copy link

Thank you @SahilVasava , that helped. I think the documentation needs to be worked on

@eklieme
Copy link

eklieme commented Jan 12, 2022

Hi Paulo,

took some time for me, but found it out. So in my setup I have a web app running on port 8080 at localhost, my backend is running at 8081.

Respectively, I configured my github provider:

baseUrl:'http:localhost:8081'
providers: {
github: {
clientId:'',
redirectUri:'http://localhost:8080',
optionalUrlParams: ['scope'],
scope: ['user:email'],
scopeDelimiter: ' ',
}
}

In my Backend, I created a post endpoint at /github/auth that takes the response from github after you called it in your frontend as given here:

this.$auth.authenticate('github')

This call will trigger github to post to your backend (do not forget the cors settings on your backend that github is allowed to call your api) with the following information:

{"code":"a code","clientId":"your client id","redirectUri":"http://localhost:8080"}

I then extracted the code and did a new post request from the backend to "https://github.com/login/oauth/access_token" as described here. This request has the following form:

{client_id='your client id', client_secret='your client secret', code='a code'}

I then get an access_token back:

{access_token='access token', expires_in=28800, refresh_token='refresh token', refresh_token_expires_in=15638400, scope='', token_type='bearer'}

Now, I queried the github user api at https://api.github.com/user with the access token in the Authorization header: "Authorization: token access_token".

Finally, I have my user information :)

Hope that helps,

Eric

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants