docs: fix authentication callback descriptions to include all query parameters (#10932)

This commit is contained in:
Shahed Nasser
2025-01-13 15:12:06 +02:00
committed by GitHub
parent 55ff7e4dcd
commit 4250c292eb
18 changed files with 178 additions and 188 deletions
@@ -144,7 +144,7 @@ const { success, authIdentity, location } = await authModuleService.authenticate
// passed to auth provider
{
// ...
callback_url: "example.com"
callback_url: "example.com",
}
)
```
@@ -176,6 +176,12 @@ if (success) {
}
```
<Note title="Tip">
For providers like Google, the `query` object contains the query parameters from the original callback URL, such as the `code` and `state` parameters.
</Note>
If the returned `success` property is `true`, the authentication with the third-party provider was successful.
![Diagram showcasing the second part of the third-party authentication flow](https://res.cloudinary.com/dza7lstvk/image/upload/v1711375123/Medusa%20Resources/third-party-auth-2_kmjxju.jpg)
@@ -41,7 +41,7 @@ module.exports = defineConfig({
},
],
},
}
},
],
})
```
@@ -60,7 +60,7 @@ module.exports = defineConfig({
},
],
},
}
},
],
})
```
@@ -63,7 +63,7 @@ module.exports = defineConfig({
],
},
},
}
},
],
})
```
@@ -59,7 +59,7 @@ It requires the following steps:
1. Authenticate the user with the [Auth Route](#login-route).
2. The auth route returns a URL to authenticate with third-party service, such as login with Google. The frontend (such as a storefront), when it receives a `location` property in the response, must redirect to the returned location.
3. Once the authentication with the third-party service finishes, it redirects back to the frontend with a `code` query parameter. So, make sure your third-party service is configured to redirect to your frontend page after successful authentication.
4. The frontend sends a request to the [Callback Route](#callback-route) passing the `code` query parameter.
4. The frontend sends a request to the [Validate Callback Route](#validate-callback-route) passing it the query parameters received from the third-party service, such as the `code` and `state` query parameters.
5. If the callback validation is successful, the frontend receives the authentication token.
6. Decode the received token in the frontend using tools like [react-jwt](https://www.npmjs.com/package/react-jwt).
- If the decoded data has an `actor_id` property, then the user is already registered. So, use this token for subsequent authenticated requests.
@@ -221,7 +221,7 @@ Redirect to that URL in the frontend to continue the authentication process with
The Medusa application defines an API route at `/auth/{actor_type}/{provider}/callback` that's useful for validating the authentication callback or redirect from third-party services like Google.
```bash
curl -X POST http://localhost:9000/auth/{actor_type}/{providers}/callback?code=123
curl -X POST http://localhost:9000/auth/{actor_type}/{providers}/callback?code=123&state=456
```
<Note title="Tip">
@@ -239,7 +239,7 @@ Its path parameters are:
### Query Parameters
This route accepts a `code` query parameter, which is the code received from the third-party provider.
This route accepts all the query parameters that the third-party service sends to the frontend after the user completes the authentication process, such as the `code` and `state` query parameters.
### Response Fields