Update OAuth2.md

This commit is contained in:
Ste Vaidis 2024-12-15 13:25:55 +02:00
parent 46e34ae28d
commit b88ebbe13d

View File

@ -42,7 +42,7 @@ A way for the `user` to tell `google` to give an access token to `xorismesiti.gr
3. Google will redirect the user back to your specified redirect_uri with an authorization code. 3. Google will redirect the user back to your specified redirect_uri with an authorization code.
<details> <details>
<summary><h3>Frontend HTTP Request to Google</h3></summary> <summary><h3>Frontend HTTP GET Request to Google</h3></summary>
```sh ```sh
GET https://accounts.google.com/o/oauth2/v2/auth? GET https://accounts.google.com/o/oauth2/v2/auth?
@ -106,7 +106,7 @@ const loginWithGoogle = () => {
<details> <details>
<summary><h3>Frontend HTTP Request to Backend</h3></summary> <summary><h3>Frontend HTTP POST Request to Backend</h3></summary>
```bash ```bash
POST https://xorismesiti.gr/api/auth/exchange-token POST https://xorismesiti.gr/api/auth/exchange-token
@ -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>Backend HTTP Request to Google</h3></summary> <summary><h3>Backend HTTP POST Request to Google</h3></summary>
- `HTTP` Method: POST - `HTTP` Method: POST
- `URL`: https://oauth2.googleapis.com/token - `URL`: https://oauth2.googleapis.com/token
@ -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>Frontend HTTP Request to Backend</h3></summary> <summary><h3>Frontend HTTP GET Request to Backend</h3></summary>
```bash ```bash
GET https://xorismesiti.gr/api/user-profile GET https://xorismesiti.gr/api/user-profile
@ -320,7 +320,7 @@ Authorization: Bearer access-token-from-backend
</details> </details>
<details> <details>
<summary><h3>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)
@ -362,7 +362,7 @@ your platform can now use it to fetch the user's Google profile and email inform
The token is included in the Authorization header of the request. The token is included in the Authorization header of the request.
<details> <details>
<summary><h3>HTTP Request</h3></summary> <summary><h3>HTTP GET Request</h3></summary>
```sh ```sh
GET https://www.googleapis.com/oauth2/v3/userinfo GET https://www.googleapis.com/oauth2/v3/userinfo
@ -398,7 +398,7 @@ Authorization: Bearer ya29.a0AfH6SMC8Op6zXZkHi2XITkDoOVzYXt3hTY6sny54UlWlxrnKlX5
</details> </details>
<details> <details>
<summary><h3>Backend Code:</h3></summary> <summary><h3>Backend GET Code</h3></summary>
```js ```js
app.get('/api/user-profile', async (req, res) => { app.get('/api/user-profile', async (req, res) => {
@ -438,7 +438,7 @@ your platform can use the refresh token (if provided) to obtain a new access tok
<details> <details>
<summary><h3>HTTP Request</h3></summary> <summary><h3>HTTP POST Request</h3></summary>
```bash ```bash
POST https://oauth2.googleapis.com/token POST https://oauth2.googleapis.com/token