- Register a new OAuth application to your github account: https://github.com/settings/developers You will get the clientID & clientSecret there.
- Run the server
go run *.go --client-id=<CLIENT_ID> --client-secret="CLIENT_SECRET"
- Visit
http://localhost:8080/
, clickLogin with github
. This will make a request to the oAuth gateway(https://github.com/login/oauth/authorize) of github with clientID & redirect_uri as flags. - Now give the authorization permission. If everything goes well, authorization server will redirect to the given redirect_uri.
- This redirected uri is handled by our server. We get the authorizationCode from request URL, & request to https://github.com/login/oauth/access_token by setting clientID, clientSecret & authz code to get the token.
- In the response, We will get the token. We then redirects to
/hello
endpoint (withaccess_token
set), which is also handled by us. - In
/hello
endpoint, we just use that access-token to get the user details fromhttps://api.github.com/user
.