diff --git a/OAuth2.md b/OAuth2.md index f1edf55..2521f4d 100644 --- a/OAuth2.md +++ b/OAuth2.md @@ -386,6 +386,11 @@ app.get('/api/user-profile', async (req, res) => { # 6. [Backend] Token Expiry and Refresh (Optional) +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. + +

HTTP Request

@@ -399,6 +404,16 @@ client_id=YOUR_GOOGLE_CLIENT_ID& client_secret=YOUR_GOOGLE_CLIENT_SECRET ``` +- `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. +
@@ -406,7 +421,7 @@ client_secret=YOUR_GOOGLE_CLIENT_SECRET ```json { - "access_token": "new-access-token", + "access_token": "ya29.a0AfH6SMC8Op6zXZkHi2XITkDoOVzYXt3hTY6sny54UlWlxrnKlX5Xv78is7BEHekVX-VoA", "token_type": "Bearer", "expires_in": 3600 } @@ -548,40 +563,4 @@ 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 -} -```