react-github-login icon indicating copy to clipboard operation
react-github-login copied to clipboard

success response

Open mirik999 opened this issue 7 years ago • 6 comments

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 ?

mirik999 avatar Nov 26 '17 11:11 mirik999

            <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.

mirik999 avatar Nov 26 '17 21:11 mirik999

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.

kruppel avatar Nov 27 '17 02:11 kruppel

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 avatar Nov 27 '17 12:11 mirik999

@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 avatar Apr 27 '18 07:04 junkboy0315

@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 avatar May 02 '18 15:05 mirik999

@mirik999 Hi, I tried that portal and find that they have some server side logic like as follows:

default

  1. server receives code
  2. server aquires access token
  3. server redirects users to '/onboarding'

btw, I made some serverless solution with AWS lamda. I hope this helps you.

junkboy0315 avatar May 03 '18 01:05 junkboy0315