简单记录一下Github OAuth认证过程

Github 既是认证服务器,也是资源服务器。

在Github上注册OAuth App:
注意Callback URL 填写,后面有用到。
http://localhost:8080/connect/github

得到token:

Client ID
ae73**************78

Client Secret
6380*******************************51f79

授权,浏览器打开:

https://github.com/login/oauth/authorize?client_id=ae73**************78&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fconnect%2Fgithub&scope=user

授权成功后,然后浏览器会被重定向到:

http://localhost:8080/connect/github?code=bcaefa087f590b47a28b

拿到 code后,后台去github换取 access token:

curl "https://github.com/login/oauth/access_token?client_id=ae73**************78&client_secret=6380*******************************51f79&code=bcaefa087f590b47a28b"
access_token=2d41d7cbfa2********************d9339bb02&scope=user&token_type=bearer

得到access token, 就可以想资源服务器获取资源。

curl "https://api.github.com/user?access_token=2d41d7cbfa2********************d9339bb02"
{
  "login": "xxx",
   ...
  "name": "Andy Han",
  "company": null,
   ...
  }

你可能感兴趣的:(简单记录一下Github OAuth认证过程)