From 6c194e64619c7f293e7af004f200ad0c05ab5128 Mon Sep 17 00:00:00 2001 From: Ste Vaidis Date: Sun, 15 Dec 2024 13:16:41 +0200 Subject: [PATCH] Update OAuth2.md --- OAuth2.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/OAuth2.md b/OAuth2.md index bd04bcd..27afa71 100644 --- a/OAuth2.md +++ b/OAuth2.md @@ -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. 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 haven’t already). 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 GET https://accounts.google.com/o/oauth2/v2/auth? response_type=code& - client_id=Ab2i34JHS9D& + client_id=ABC34JHS9D& redirect_uri=https://xorismesiti.gr/callback& scope=email%20profile& state=xyz123 @@ -61,28 +61,25 @@ GET https://accounts.google.com/o/oauth2/v2/auth? -

HTTP Response

```bash 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-Length: 0 ```
- -

Frontent Code

```js // Redirect to Google's OAuth 2.0 endpoint when user clicks login 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 scope = 'email profile'; // Scopes you're requesting (email, profile, etc.) const state = 'random-state-value'; // For CSRF protection