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
@@ -54,7 +54,7 @@ export const multiPartsHighlights1 = [
```ts highlights={multiPartsHighlights1}
import {
createInventoryItemsWorkflow,
useQueryGraphStep
useQueryGraphStep,
} from "@medusajs/medusa/core-flows"
import { createWorkflow } from "@medusajs/framework/workflows-sdk"
@@ -66,8 +66,8 @@ export const createMultiPartProductsWorkflow = createWorkflow(
entity: "stock_location",
fields: ["*"],
filters: {
name: "European Warehouse"
}
name: "European Warehouse",
},
})
const inventoryItems = createInventoryItemsWorkflow.runAsStep({
@@ -79,9 +79,9 @@ export const createMultiPartProductsWorkflow = createWorkflow(
location_levels: [
{
stocked_quantity: 100,
location_id: stockLocations[0].id
}
]
location_id: stockLocations[0].id,
},
],
},
{
sku: "WHEEL",
@@ -89,9 +89,9 @@ export const createMultiPartProductsWorkflow = createWorkflow(
location_levels: [
{
stocked_quantity: 100,
location_id: stockLocations[0].id
}
]
location_id: stockLocations[0].id,
},
],
},
{
sku: "SEAT",
@@ -99,12 +99,12 @@ export const createMultiPartProductsWorkflow = createWorkflow(
location_levels: [
{
stocked_quantity: 100,
location_id: stockLocations[0].id
}
]
}
]
}
location_id: stockLocations[0].id,
},
],
},
],
},
})
// TODO create the product
@@ -127,11 +127,11 @@ export const multiPartHighlights2 = [
```ts highlights={multiPartHighlights2}
import {
// ...
transform
transform,
} from "@medusajs/framework/workflows-sdk"
import {
// ...
createProductsWorkflow
createProductsWorkflow,
} from "@medusajs/medusa/core-flows"
export const createMultiPartProductsWorkflow = createWorkflow(
@@ -140,7 +140,7 @@ export const createMultiPartProductsWorkflow = createWorkflow(
// ...
const inventoryItemIds = transform({
inventoryItems
inventoryItems,
}, (data) => {
return data.inventoryItems.map((inventoryItem) => {
return {
@@ -161,24 +161,24 @@ export const createMultiPartProductsWorkflow = createWorkflow(
prices: [
{
amount: 100,
currency_code: "usd"
}
currency_code: "usd",
},
],
options: {
"Default Option": "Default Variant"
"Default Option": "Default Variant",
},
inventory_items: inventoryItemIds
}
inventory_items: inventoryItemIds,
},
],
options: [
{
title: "Default Option",
values: ["Default Variant"]
}
]
}
]
}
values: ["Default Variant"],
},
],
},
],
},
})
}
)
@@ -235,21 +235,21 @@ export const createBundledProducts = createWorkflow(
prices: [
{
amount: 10,
currency_code: "usd"
}
currency_code: "usd",
},
],
options: {
"Default Option": "Default Variant"
"Default Option": "Default Variant",
},
manage_inventory: true
}
manage_inventory: true,
},
],
options: [
{
title: "Default Option",
values: ["Default Variant"]
}
]
values: ["Default Variant"],
},
],
},
{
title: "Pants",
@@ -259,21 +259,21 @@ export const createBundledProducts = createWorkflow(
prices: [
{
amount: 10,
currency_code: "usd"
}
currency_code: "usd",
},
],
options: {
"Default Option": "Default Variant"
"Default Option": "Default Variant",
},
manage_inventory: true
}
manage_inventory: true,
},
],
options: [
{
title: "Default Option",
values: ["Default Variant"]
}
]
values: ["Default Variant"],
},
],
},
{
title: "Shoes",
@@ -283,24 +283,24 @@ export const createBundledProducts = createWorkflow(
prices: [
{
amount: 10,
currency_code: "usd"
}
currency_code: "usd",
},
],
options: {
"Default Option": "Default Variant"
"Default Option": "Default Variant",
},
manage_inventory: true
}
manage_inventory: true,
},
],
options: [
{
title: "Default Option",
values: ["Default Variant"]
}
]
}
]
}
values: ["Default Variant"],
},
],
},
],
},
})
// TODO re-retrieve with inventory
@@ -321,10 +321,10 @@ export const bundledHighlights2 = [
```ts highlights={bundledHighlights2}
import {
// ...
transform
transform,
} from "@medusajs/framework/workflows-sdk"
import {
useQueryGraphStep
useQueryGraphStep,
} from "@medusajs/medusa/core-flows"
export const createBundledProducts = createWorkflow(
@@ -332,7 +332,7 @@ export const createBundledProducts = createWorkflow(
() => {
// ...
const productIds = transform({
products
products,
}, (data) => data.products.map((product) => product.id))
// @ts-ignore
@@ -340,19 +340,19 @@ export const createBundledProducts = createWorkflow(
entity: "product",
fields: [
"variants.*",
"variants.inventory_items.*"
"variants.inventory_items.*",
],
filters: {
id: productIds
}
id: productIds,
},
})
const inventoryItemIds = transform({
productsWithInventory
productsWithInventory,
}, (data) => {
return data.productsWithInventory.map((product) => {
return {
inventory_item_id: product.variants[0].inventory_items?.[0]?.inventory_item_id
inventory_item_id: product.variants[0].inventory_items?.[0]?.inventory_item_id,
}
})
})
@@ -387,24 +387,24 @@ export const createBundledProducts = createWorkflow(
prices: [
{
amount: 30,
currency_code: "usd"
}
currency_code: "usd",
},
],
options: {
"Default Option": "Default Variant"
"Default Option": "Default Variant",
},
inventory_items: inventoryItemIds,
}
},
],
options: [
{
title: "Default Option",
values: ["Default Variant"]
}
]
}
]
}
values: ["Default Variant"],
},
],
},
],
},
}).config({ name: "create-bundled-product" })
}
)
@@ -36,15 +36,15 @@ For example:
<CodeTab label="Using Workflow" value="workflow">
```ts
import { createPaymentCollectionForCartWorkflow } from "@medusajs/medusa/core-flows";
import { createPaymentCollectionForCartWorkflow } from "@medusajs/medusa/core-flows"
// ...
await createPaymentCollectionForCartWorkflow(req.scope)
.run({
input: {
cart_id: "cart_123"
}
cart_id: "cart_123",
},
})
```
@@ -77,7 +77,7 @@ For example:
<CodeTab label="Using Workflow" value="workflow">
```ts
import { createPaymentSessionsWorkflow } from "@medusajs/medusa/core-flows";
import { createPaymentSessionsWorkflow } from "@medusajs/medusa/core-flows"
// ...
@@ -86,7 +86,7 @@ const { result: paymentSesion } = await createPaymentSessionsWorkflow(req.scope)
input: {
payment_collection_id: "paycol_123",
provider_id: "stripe",
}
},
})
```
@@ -124,13 +124,13 @@ For example:
<CodeTab label="Using Step" value="workflow">
```ts
import { authorizePaymentSessionStep } from "@medusajs/medusa/core-flows";
import { authorizePaymentSessionStep } from "@medusajs/medusa/core-flows"
// ...
authorizePaymentSessionStep({
id: "payses_123",
context: {}
context: {},
})
```
@@ -140,7 +140,7 @@ authorizePaymentSessionStep({
```ts
const payment = authorizePaymentSessionStep({
id: "payses_123",
context: {}
context: {},
})
```