Update OAuth2.md

This commit is contained in:
Ste Vaidis 2024-12-15 10:24:42 +02:00
parent a78e2a37f1
commit 01f7335a94

View File

@ -1,3 +1,12 @@
OAuth2 Flow:
1. User clicks "Login with Google" on your platform (xorismesiti.gr).
2. Authorization Request: Redirect to Google's authorization endpoint, requesting the user's profile and email.
3. User Login and Consent: User logs in to Google and grants permissions.
4. Authorization Code Response: Google redirects back to your platform with an authorization code.
5. Access Token Request: Exchange the authorization code for an access token.
6. Access Protected Resources: Use the access token to fetch the user's Google profile and email.
7. Token Refresh (Optional): If the token expires, use the refresh token to get a new access token.
# 1. Authorization Request (User Initiates Login) # 1. Authorization Request (User Initiates Login)
@ -137,3 +146,40 @@ Authorization: Bearer ya29.a0AfH6SMC8Op6zXZkHi2XITkDoOVzYXt3hTY6sny54UlWlxrnKlX5
``` ```
# 7. Refreshing the Access Token (If Necessary)
If the access token expires,
your platform can use the refresh token (if provided) to obtain a new access token without requiring the user to log in again.
- `URL`: https://oauth2.googleapis.com/token
- `HTTP` Method: POST
- `Headers`:
- `Content`-Type: application/x-www-form-urlencoded
- `Body` Parameters:
- `grant_type`=refresh_token: This indicates the refresh token flow.
- `refresh_token`: The refresh token obtained in step 5.
- `client_id`: Your Google API client ID.
- `client_secret`: Your Google API client secret.
**Request**
```sh
POST https://oauth2.googleapis.com/token
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&
refresh_token=1//04d5XHqmn6Hdy3wTf5OYDP1SyBa74zEFURjddQ2A1cFw78PY13pQyWhlD2A6XhDQtKlrjAqU4kS3vGdMvckw&
client_id=YOUR_GOOGLE_CLIENT_ID&
client_secret=YOUR_GOOGLE_CLIENT_SECRET
``
**Response**
```json
{
"access_token": "ya29.a0AfH6SMC8Op6zXZkHi2XITkDoOVzYXt3hTY6sny54UlWlxrnKlX5Xv78is7BEHekVX-VoA",
"token_type": "Bearer",
"expires_in": 3600
}
```