react-github-login
react-github-login copied to clipboard
success response
Success response return any code: { string } , but in scope i write user , without scope tag the same problem. How can i get accessToken nickname picture email ?
<GitHubLogin
clientId="myidstring"
redirectUri=""
onSuccess={this.responseGithub}
buttonText="github"
className="github-button"
/>
and every time when i click to the button i get {code: "1f34f7fbcdab96e007e0"} - string changing every time. pls help to resolve this problem.
Hi @mirik999, are you exchanging the temporary code
for an access token? If not, I'd suggest reviewing the documentation, https://developer.github.com/apps/building-integrations/setting-up-and-registering-oauth-apps/about-authorization-options-for-oauth-apps/#2-users-are-redirected-back-to-your-site-by-github, and seeing if that works.
Note that you'll need to make a request with your client secret in order to acquire an access token. Since that's something you shouldn't expose, I'd recommend handling the access token request on the server side.
Hope that helps.
i understood and i tried and i got an errors about CORS problems but facebookLogin (react-facebook-login) works well without any problems.
responseGithub = (res) => { const data = { client_id: 'myclientid', client_secret: 'myclientsecret', code: res.code } this.props.githubLogin(data); // -> axios.post('https://github.com/login/oauth/access_token', { data }).then(res => console.log(res)) }
@mirik999 Hi, I faced a same problem and had a very hard fight. As a result, my conclusion is that Github OAuth is not ready for full front end authentication.
It is impossible to get an access token from the front end because it will not return the 'Allow-Control-Allow-Origin' header from the following URL. https://github.com/login/oauth/access_token
You can not get an access token from the browser.
They expect to exchange code
and accessToken
from the server.
Facebook works well as it is ready for full front end authentication.
@junkboy0315 thanx for taking the time to explain. But i think only this module (react-github-login) doesnt work because in http://hashnode.com portal everythinl working fine. This site also built with react
@mirik999 Hi, I tried that portal and find that they have some server side logic like as follows:
- server receives code
- server aquires access token
- server redirects users to '/onboarding'
btw, I made some serverless solution with AWS lamda. I hope this helps you.