oas: update examples and security tags (#5256)

- Change cURL examples to use `x-medusa-access-token` instead of bearer
- Add `jwt_token` to `securitySchemes` and update existing `api_token`.
This commit is contained in:
Shahed Nasser authored and GitHub committed 2023-09-29 19:43:57 +00:00
1 parent d45e3e83d3
commit 22130ecb63
274 files changed
+541 -336

No files matched your search

+7 -80
View File
@@ -366,89 +366,16 @@ components:
type: "unknown_error"
securitySchemes:
api_token:
type: http
type: apiKey
x-displayName: API Token
description: |
Use a user's API Token to send authenticated requests.
### How to Add API Token to a User
At the moment, there's no direct way of adding an API Token for a user. The only way it can be done is through directly editing the database.
If you're using a PostgreSQL database, you can run the following commands in your command line to add API token:
```bash
psql -d <DB_NAME> -U <DB_USER>
UPDATE public.user SET api_token='<API_TOKEN>' WHERE email='<USER_EMAIL>';
```
Where:
- `<DB_NAME>` is the name of the database schema you use for the Medusa server.
- `<DB_USER>` is the name of the user that has privileges over the database schema.
- `<API_TOKEN>` is the API token you want to associate with the user. You can use [this tool to generate a random token](https://randomkeygen.com/).
- `<USER_EMAIL>` is the email address of the admin user you want to have this API token.
### How to Use the API Token
The API token can be used for Bearer Authentication. It's passed in the `Authorization` header as the following:
```
Authorization: Bearer {api_token}
```
In this API reference, you'll find in the cURL request samples the use of `{api_token}`. This is where you must pass the API token.
If you're following along with the JS Client request samples, you must provide the `apiKey` option when creating the Medusa client:
```ts
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3, apiKey: '{api_token}' })
```
If you're using Medusa React, you can pass the `apiKey` prop to `MedusaProvider`:
```tsx
<MedusaProvider
apiKey='api_token}'
//...
>
```
in: header
name: x-medusa-access-token
jwt_token:
type: http
x-displayName: JWT Token
scheme: bearer
cookie_auth:
type: apiKey
in: cookie
name: connect.sid
x-displayName: Cookie Session ID
description: |
Use a cookie session to send authenticated requests.
### How to Obtain the Cookie Session
If you're sending requests through a browser, using JS Client, or using tools like Postman, the cookie session should be automatically set when the admin user is logged in.
If you're sending requests using cURL, you must set the Session ID in the cookie manually.
To do that, send a request to [authenticate the user](#tag/Auth/operation/PostAuth) and pass the cURL option `-v`:
```bash
curl -v --location --request POST 'https://medusa-url.com/admin/auth' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "user@example.com",
"password": "supersecret"
}'
```
The headers will be logged in the terminal as well as the response. You should find in the headers a Cookie header similar to this:
```bash
Set-Cookie: connect.sid=s%3A2Bu8BkaP9JUfHu9rG59G16Ma0QZf6Gj1.WT549XqX37PN8n0OecqnMCq798eLjZC5IT7yiDCBHPM;
```
Copy the value after `connect.sid` (without the `;` at the end) and pass it as a cookie in subsequent requests as the following:
```bash
curl --location --request GET 'https://medusa-url.com/admin/products' \
--header 'Cookie: connect.sid={sid}'
```
Where `{sid}` is the value of `connect.sid` that you copied.
x-displayName: Cookie Session ID
+4
View File
@@ -241,6 +241,10 @@ components:
message: "An unknown error occurred."
type: "unknown_error"
securitySchemes:
jwt_token:
type: http
x-displayName: JWT Token
scheme: bearer
cookie_auth:
type: apiKey
x-displayName: Cookie Session ID