Update OAuth2.md

This commit is contained in:
Ste Vaidis 2024-12-15 13:16:41 +02:00
parent f800311ed9
commit 6c194e6461

View File

@ -37,7 +37,7 @@ A way for the `user` to tell `google` to give an access token to `xorismesiti.gr
# 1. [Frontend] Request Authorization code # 1. [Frontend] Request Authorization code
1. The use clicks a "Login with Google" button with a URL to Google's OAuth 2.0 authorization endpoint and redirects the user there. 1. The use clicks a "Login with Google" link button with a URL to Google's OAuth 2.0 authorization endpoint and redirects the user there.
2. After this redirection, the user will log in to Google and grant permissions (if they havent already). 2. After this redirection, the user will log in to Google and grant permissions (if they havent already).
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.
@ -47,7 +47,7 @@ A way for the `user` to tell `google` to give an access token to `xorismesiti.gr
```sh ```sh
GET https://accounts.google.com/o/oauth2/v2/auth? GET https://accounts.google.com/o/oauth2/v2/auth?
response_type=code& response_type=code&
client_id=Ab2i34JHS9D& client_id=ABC34JHS9D&
redirect_uri=https://xorismesiti.gr/callback& redirect_uri=https://xorismesiti.gr/callback&
scope=email%20profile& scope=email%20profile&
state=xyz123 state=xyz123
@ -61,28 +61,25 @@ GET https://accounts.google.com/o/oauth2/v2/auth?
</details> </details>
<details> <details>
<summary><h3>HTTP Response</h3></summary> <summary><h3>HTTP Response</h3></summary>
```bash ```bash
HTTP/1.1 302 Found HTTP/1.1 302 Found
Location: https://xorismesiti.gr/api/auth/callback?code=4/0AX4XfWgyVyz-uT8k7WiyLg0Q&state=random-state-value Location: https://xorismesiti.gr/api/auth/callback?code=4/0AX4XfWgyVyz-uT8k7WiyLg0Q&state=xyz123
Content-Type: text/html; charset=UTF-8 Content-Type: text/html; charset=UTF-8
Content-Length: 0 Content-Length: 0
``` ```
</details> </details>
<details> <details>
<summary><h3>Frontent Code</h3></summary> <summary><h3>Frontent Code</h3></summary>
```js ```js
// Redirect to Google's OAuth 2.0 endpoint when user clicks login // Redirect to Google's OAuth 2.0 endpoint when user clicks login
const loginWithGoogle = () => { const loginWithGoogle = () => {
const clientId = 'YOUR_GOOGLE_CLIENT_ID'; // Replace with your actual Google Client ID const clientId = 'ABC34JHS9D'; // Replace with your actual Google Client ID
const redirectUri = 'https://xorismesiti.gr/api/auth/callback'; // Backend URL where Google will send the user after login const redirectUri = 'https://xorismesiti.gr/api/auth/callback'; // Backend URL where Google will send the user after login
const scope = 'email profile'; // Scopes you're requesting (email, profile, etc.) const scope = 'email profile'; // Scopes you're requesting (email, profile, etc.)
const state = 'random-state-value'; // For CSRF protection const state = 'random-state-value'; // For CSRF protection