Sign in --GitHub achieve

Here Insert Picture Description

English document attached GitHub OAuth address

Step 1: The user clicks the login button, button bindings: https:? //Github.com/login/oauth/authorize ..

parameter name type of data description
client_id String Click here to sign in OAuth Apps, here you will see Client_id, Client Secret
redirect_uri String When a user authorized to log on automatically redirect page
login String The use of a specific application account login and authorization.
scope String To obtain a range of information
state String A random number, used to prevent the cross-domain attacks
示例:
https://github.com/login/oauth/authorize?
client_id=ddaec34bf350asfdqwe&
redirect_uri=http://localhost:8080/callback&
scope=user&
state=2304

Step 2: The first step is redirected to redirect_uri provided, along with the parameter code, state

Visit: https: //github.com/login/oauth/access_token

parameter name type of data description
client_id String Click here to sign in OAuth Apps, here you will see Client_id, Client Secret
redirect_uri String After successfully acquiring the access token redirection page
client_secret String Click here to sign in OAuth Apps, here you will see Client_id, Client Secret
code String The first step in the return parameters, it is very important!
state String Parameters Step returned to keep a state set to the first step

Note: This is the POST request, can be simulated by means of OkHttp Post request, and acquires the access token, token_type

示例:access_token=e72e16c7e42f292c4343er710c838347ae178b4a&token_type=bearer

Step 3: Split string by getting to the access token, use OkHttp initiate a request for user information, visit: https: //api.github.com/user? access_token = ...

The information is returned to the user

Released two original articles · won praise 0 · Views 96

Guess you like

Origin blog.csdn.net/Lohaks/article/details/104678573