diff --git a/OAuth2.md b/OAuth2.md index 1787491..a949ee2 100644 --- a/OAuth2.md +++ b/OAuth2.md @@ -154,7 +154,7 @@ export default Callback; -# 3. Backend (Node.js): Handle Token Exchange +# 3. [Backend] Exchange Code with Token 1. The backend receives the authorization `code` from the frontend, 2. The backend makes a `POST` request to Google token endpoint, to exchange the authorization `code` for the `access_token` and optionally a `refresh token` @@ -336,7 +336,7 @@ Authorization: Bearer access-token-from-backend
-

HTTP Request

+

HTTP Response

```json { @@ -386,6 +386,34 @@ app.get('/api/user-profile', async (req, res) => { # 6. [Backend] Token Expiry and Refresh (Optional) +
+

HTTP Request

+ +```bash +POST https://oauth2.googleapis.com/token +Content-Type: application/x-www-form-urlencoded + +grant_type=refresh_token& +refresh_token=refresh-token-from-backend& +client_id=YOUR_GOOGLE_CLIENT_ID& +client_secret=YOUR_GOOGLE_CLIENT_SECRET +``` + +
+ +
+

HTTP Response

+ +```json +{ + "access_token": "new-access-token", + "token_type": "Bearer", + "expires_in": 3600 +} +``` + +
+

Example Backend Code:

@@ -422,6 +450,15 @@ app.post('/api/auth/refresh-token', async (req, res) => { + + + + + + + + + ```sh GET https://xorismesiti.gr/callback? code=4/0AX4XfWgNmGZVbV7Kdr8Q9yVyzIYBnbbBdLfX39ZaE8m0w8zT8jKRLl7w-uT8k7WiyLg0Q&