Update OAuth2.md
This commit is contained in:
parent
a0614514e8
commit
3da5e9ef4f
41
OAuth2.md
41
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
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><h3>HTTP Request</h3></summary>
|
||||
<summary><h3>HTTP Response</h3></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
@ -386,6 +386,34 @@ app.get('/api/user-profile', async (req, res) => {
|
||||
|
||||
# 6. [Backend] Token Expiry and Refresh (Optional)
|
||||
|
||||
<details>
|
||||
<summary><h3>HTTP Request</h3></summary>
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><h3>HTTP Response</h3></summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"access_token": "new-access-token",
|
||||
"token_type": "Bearer",
|
||||
"expires_in": 3600
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><h3>Example Backend Code:</h3></summary>
|
||||
|
||||
@ -422,6 +450,15 @@ app.post('/api/auth/refresh-token', async (req, res) => {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
```sh
|
||||
GET https://xorismesiti.gr/callback?
|
||||
code=4/0AX4XfWgNmGZVbV7Kdr8Q9yVyzIYBnbbBdLfX39ZaE8m0w8zT8jKRLl7w-uT8k7WiyLg0Q&
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user