Update OAuth2.md

This commit is contained in:
Ste Vaidis 2024-12-15 13:21:16 +02:00
parent 1d5fb5512c
commit be82269206

View File

@ -189,7 +189,7 @@ export default Callback;
4. The backend will exchange the `code` for an `access_token` and `refresh_token`, which are sent back to the frontend or stored securely for subsequent API calls. 4. The backend will exchange the `code` for an `access_token` and `refresh_token`, which are sent back to the frontend or stored securely for subsequent API calls.
<details> <details>
<summary><h3>HTTP Request</h3></summary> <summary><h3>Backend HTTP Request to Google</h3></summary>
- `HTTP` Method: POST - `HTTP` Method: POST
- `URL`: https://oauth2.googleapis.com/token - `URL`: https://oauth2.googleapis.com/token
@ -216,7 +216,7 @@ client_secret=YOUR_GOOGLE_CLIENT_SECRET
</details> </details>
<details> <details>
<summary><h3>HTTP Response</h3></summary> <summary><h3>HTTP Response from Google</h3></summary>
```json ```json
{ {
@ -231,7 +231,7 @@ client_secret=YOUR_GOOGLE_CLIENT_SECRET
</details> </details>
<details> <details>
<summary><h3>Example Backend Code:</h3></summary> <summary><h3>Backend Code:</h3></summary>
```js ```js
const express = require('express'); const express = require('express');
@ -291,7 +291,7 @@ Once the backend exchanges the `code` for the `access_token`,
the frontend can use it to make authenticated requests to the backend or Google APIs the frontend can use it to make authenticated requests to the backend or Google APIs
<details> <details>
<summary><h3>HTTP Request</h3></summary> <summary><h3>Frontend HTTP Request to Backend</h3></summary>
```bash ```bash
GET https://xorismesiti.gr/api/user-profile GET https://xorismesiti.gr/api/user-profile
@ -301,7 +301,7 @@ Authorization: Bearer access-token-from-backend
</details> </details>
<details> <details>
<summary><h3>HTTP Response</h3></summary> <summary><h3>Frontend HTTP Response from Backend</h3></summary>
```json ```json
{ {
@ -320,7 +320,7 @@ Authorization: Bearer access-token-from-backend
</details> </details>
<details> <details>
<summary><h3>Example Frontend Code:</h3></summary> <summary><h3>Frontend Code:</h3></summary>
```js ```js
// After receiving the token, store it in the frontend (e.g., localStorage or context) // After receiving the token, store it in the frontend (e.g., localStorage or context)
@ -398,7 +398,7 @@ Authorization: Bearer ya29.a0AfH6SMC8Op6zXZkHi2XITkDoOVzYXt3hTY6sny54UlWlxrnKlX5
</details> </details>
<details> <details>
<summary><h3>Example Backend Code:</h3></summary> <summary><h3>Backend Code:</h3></summary>
```js ```js
app.get('/api/user-profile', async (req, res) => { app.get('/api/user-profile', async (req, res) => {