This is my memo while learning OAuth 2.0.
https://tools.ietf.org/html/rfc6749
+--------+ +---------------+
| |--(A)- Authorization Request ->| Resource |
| | | Owner |
| |<-(B)-- Authorization Grant ---| |
| | +---------------+
| |
| | +---------------+
| |--(C)-- Authorization Grant -->| Authorization |
| Client | | Server |
| |<-(D)----- Access Token -------| |
| | +---------------+
| |
| | +---------------+
| |--(E)----- Access Token ------>| Resource |
| | | Server |
| |<-(F)--- Protected Resource ---| |
+--------+ +---------------+
1.3. Authorization Grant … This specification defines four grant types – authorization code, implicit, resource owner passwordcredentials, and client credentials
In Google Identity, they implement the Authorization Grant with an authorization code.
Access Tokens are used when a client request resources (final data which we want to get, like Username, e-mail address, etc.).
In case of Google (web), we should issue client ID
and client secret
beforhand.
I followed the official instruction
http://localhost
https://accounts.google.com/o/oauth2/v2/auth?scope=https%3A//mail.google.com/&access_type=offline&include_granted_scopes=true&response_type=code&state=state_parameter_passthrough_value&redirect_uri=http%3A//localhost&client_id={{ your_client_id }}
http://localhost/?state=state_parameter_passthrough_value&code={{ authorization_code_like_4/0... }}&scope=https://mail.google.com/
. The parameter code
is your Authorization code.$ curl --data "code={{ authorization_code }}&client_id={{ your_client_id }}&client_secret={{ your_client_secret }}&redirect_uri={{ same_as_the_previous_request}}&grant_type=authorization_code" -H "Content-Type: application/x-www-form-urlencoded" https://oauth2.googleapis.com/token
{
"access_token": "{{ Long_access_token }}",
"expires_in": 3599,
"refresh_token": "1//092sdJTC5ksTJCgYIARAAGAkSNwF-L9IrsFZhCoyq_q_Ii4iNRSonmHT_hCbL29Ghe4SbY8pH9Ab4eXchVBUqnVtTpDrr-3UzKwQ",
"scope": "https://mail.google.com/",
"token_type": "Bearer"
}
You can’t access this endpoint twice (the API returns invalid_grant
, Bad Request 400).
curl -d -X -POST --header "Content-type:application/x-www-form-urlencoded" \
https://oauth2.googleapis.com/revoke?token={token}
Here is a good demo.