chore(oas): Fix OAS related to JWT authentication (#5448)

* chore(oas): Fix OAS related to JWT authentication

* generate openapi spec files

* remove L option in curl examples
This commit is contained in:
Shahed Nasser
2023-10-23 11:48:02 +03:00
committed by GitHub
parent 1a10822cae
commit c67d490db3
34 changed files with 65 additions and 93 deletions
@@ -5,7 +5,7 @@ import { SetRelation, Merge } from "../core/ModelUtils"
export interface AdminBearerAuthRes { export interface AdminBearerAuthRes {
/** /**
* Access token for subsequent authorization. * Access token that can be used to send authenticated requests.
*/ */
accessToken?: string access_token?: string
} }
@@ -5,7 +5,7 @@ import { SetRelation, Merge } from "../core/ModelUtils"
export interface StoreBearerAuthRes { export interface StoreBearerAuthRes {
/** /**
* Access token for subsequent authorization. * Access token that can be used to send authenticated requests.
*/ */
accessToken?: string access_token?: string
} }
@@ -10,10 +10,7 @@ import { AdminPostAuthReq } from "./create-session"
* operationId: "PostToken" * operationId: "PostToken"
* summary: "User Login (JWT)" * summary: "User Login (JWT)"
* x-authenticated: false * x-authenticated: false
* description: "After a successful login, a JWT token is returned for subsequent authorization." * description: "After a successful login, a JWT token is returned, which can be used to send authenticated requests."
* parameters:
* - (body) email=* {string} The User's email.
* - (body) password=* {string} The User's password.
* requestBody: * requestBody:
* content: * content:
* application/json: * application/json:
@@ -31,14 +28,14 @@ import { AdminPostAuthReq } from "./create-session"
* email: 'user@example.com', * email: 'user@example.com',
* password: 'supersecret' * password: 'supersecret'
* }) * })
* .then(({ accessToken }) => { * .then(({ access_token }) => {
* console.log(accessToekn); * console.log(access_token);
* }); * });
* - lang: Shell * - lang: Shell
* label: cURL * label: cURL
* source: | * source: |
* curl --location --request POST 'https://medusa-url.com/admin/auth/token' \ * curl -X POST '{backend_url}/admin/auth/token' \
* --header 'Content-Type: application/json' \ * -H 'Content-Type: application/json' \
* --data-raw '{ * --data-raw '{
* "email": "user@example.com", * "email": "user@example.com",
* "password": "supersecret" * "password": "supersecret"
@@ -44,8 +44,8 @@ export type AdminAuthRes = {
* @schema AdminBearerAuthRes * @schema AdminBearerAuthRes
* type: object * type: object
* properties: * properties:
* accessToken: * access_token:
* description: Access token for subsequent authorization. * description: Access token that can be used to send authenticated requests.
* type: string * type: string
*/ */
export type AdminBearerAuthRes = { export type AdminBearerAuthRes = {
@@ -11,7 +11,7 @@
* label: cURL * label: cURL
* source: | * source: |
* curl -X DELETE '{backend_url}/store/auth' \ * curl -X DELETE '{backend_url}/store/auth' \
* -H 'Cookie: connect.sid={sid}' * -H 'Authorization: Bearer {access_token}'
* security: * security:
* - cookie_auth: [] * - cookie_auth: []
* - jwt_token: [] * - jwt_token: []
@@ -24,7 +24,7 @@ import { defaultRelations } from "."
* label: cURL * label: cURL
* source: | * source: |
* curl '{backend_url}/store/auth' \ * curl '{backend_url}/store/auth' \
* -H 'Cookie: connect.sid={sid}' * -H 'Authorization: Bearer {access_token}'
* security: * security:
* - cookie_auth: [] * - cookie_auth: []
* - jwt_token: [] * - jwt_token: []
@@ -6,14 +6,11 @@ import { validator } from "../../../../utils/validator"
import { StorePostAuthReq } from "./create-session" import { StorePostAuthReq } from "./create-session"
/** /**
* @oas [post] /store/token * @oas [post] /store/auth/token
* operationId: "PostToken" * operationId: "PostToken"
* summary: "Customer Login (JWT)" * summary: "Customer Login (JWT)"
* x-authenticated: false * x-authenticated: false
* description: "After a successful login, a JWT token is returned for subsequent authorization." * description: "After a successful login, a JWT token is returned, which can be used to send authenticated requests."
* parameters:
* - (body) email=* {string} The User's email.
* - (body) password=* {string} The User's password.
* requestBody: * requestBody:
* content: * content:
* application/json: * application/json:
@@ -27,18 +24,18 @@ import { StorePostAuthReq } from "./create-session"
* source: | * source: |
* import Medusa from "@medusajs/medusa-js" * import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.store.auth.getToken({ * medusa.auth.getToken({
* email: 'user@example.com', * email: 'user@example.com',
* password: 'supersecret' * password: 'supersecret'
* }) * })
* .then(({ accessToken }) => { * .then(({ access_token }) => {
* console.log(accessToken); * console.log(access_token);
* }); * });
* - lang: Shell * - lang: Shell
* label: cURL * label: cURL
* source: | * source: |
* curl --location --request POST 'https://medusa-url.com/store/auth/token' \ * curl -X POST '{backend_url}/store/auth/token' \
* --header 'Content-Type: application/json' \ * -H 'Content-Type: application/json' \
* --data-raw '{ * --data-raw '{
* "email": "user@example.com", * "email": "user@example.com",
* "password": "supersecret" * "password": "supersecret"
@@ -46,8 +46,8 @@ export type StoreAuthRes = {
* @schema StoreBearerAuthRes * @schema StoreBearerAuthRes
* type: object * type: object
* properties: * properties:
* accessToken: * access_token:
* description: Access token for subsequent authorization. * description: Access token that can be used to send authenticated requests.
* type: string * type: string
*/ */
export type StoreBearerAuthRes = { export type StoreBearerAuthRes = {
@@ -46,7 +46,7 @@ import { validator } from "../../../../utils/validator"
* label: cURL * label: cURL
* source: | * source: |
* curl -X POST '{backend_url}/store/customers/me/addresses' \ * curl -X POST '{backend_url}/store/customers/me/addresses' \
* -H 'Cookie: connect.sid={sid}' \ * -H 'Authorization: Bearer {access_token}' \
* -H 'Content-Type: application/json' \ * -H 'Content-Type: application/json' \
* --data-raw '{ * --data-raw '{
* "address": { * "address": {
@@ -28,7 +28,7 @@ import CustomerService from "../../../../services/customer"
* label: cURL * label: cURL
* source: | * source: |
* curl -X DELETE '{backend_url}/store/customers/me/addresses/{address_id}' \ * curl -X DELETE '{backend_url}/store/customers/me/addresses/{address_id}' \
* -H 'Cookie: connect.sid={sid}' * -H 'Authorization: Bearer {access_token}'
* security: * security:
* - cookie_auth: [] * - cookie_auth: []
* - jwt_token: [] * - jwt_token: []
@@ -24,7 +24,7 @@ import CustomerService from "../../../../services/customer"
* label: cURL * label: cURL
* source: | * source: |
* curl '{backend_url}/store/customers/me' \ * curl '{backend_url}/store/customers/me' \
* -H 'Cookie: connect.sid={sid}' * -H 'Authorization: Bearer {access_token}'
* security: * security:
* - cookie_auth: [] * - cookie_auth: []
* - jwt_token: [] * - jwt_token: []
@@ -28,7 +28,7 @@ import { PaymentProvider } from "../../../../models"
* label: cURL * label: cURL
* source: | * source: |
* curl '{backend_url}/store/customers/me/payment-methods' \ * curl '{backend_url}/store/customers/me/payment-methods' \
* -H 'Cookie: connect.sid={sid}' * -H 'Authorization: Bearer {access_token}'
* security: * security:
* - cookie_auth: [] * - cookie_auth: []
* - jwt_token: [] * - jwt_token: []
@@ -158,7 +158,7 @@ import { DateComparisonOperator } from "../../../../types/common"
* label: cURL * label: cURL
* source: | * source: |
* curl '{backend_url}/store/customers/me/orders' \ * curl '{backend_url}/store/customers/me/orders' \
* -H 'Cookie: connect.sid={sid}' * -H 'Authorization: Bearer {access_token}'
* security: * security:
* - cookie_auth: [] * - cookie_auth: []
* - jwt_token: [] * - jwt_token: []
@@ -37,7 +37,7 @@ import { validator } from "../../../../utils/validator"
* label: cURL * label: cURL
* source: | * source: |
* curl -X POST '{backend_url}/store/customers/me/addresses/{address_id}' \ * curl -X POST '{backend_url}/store/customers/me/addresses/{address_id}' \
* -H 'Cookie: connect.sid={sid}' \ * -H 'Authorization: Bearer {access_token}' \
* -H 'Content-Type: application/json' \ * -H 'Content-Type: application/json' \
* --data-raw '{ * --data-raw '{
* "first_name": "Gina" * "first_name": "Gina"
@@ -37,7 +37,7 @@ import { IsType } from "../../../../utils/validators/is-type"
* label: cURL * label: cURL
* source: | * source: |
* curl -X POST '{backend_url}/store/customers/me' \ * curl -X POST '{backend_url}/store/customers/me' \
* -H 'Cookie: connect.sid={sid}' \ * -H 'Authorization: Bearer {access_token}' \
* -H 'Content-Type: application/json' \ * -H 'Content-Type: application/json' \
* --data-raw '{ * --data-raw '{
* "first_name": "Laury" * "first_name": "Laury"
@@ -4,6 +4,6 @@ medusa.admin.auth.getToken({
email: 'user@example.com', email: 'user@example.com',
password: 'supersecret' password: 'supersecret'
}) })
.then(({ accessToken }) => { .then(({ access_token }) => {
console.log(accessToekn); console.log(access_token);
}); });
@@ -1,5 +1,5 @@
curl --location --request POST 'https://medusa-url.com/admin/auth/token' \ curl -X POST '{backend_url}/admin/auth/token' \
--header 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
--data-raw '{ --data-raw '{
"email": "user@example.com", "email": "user@example.com",
"password": "supersecret" "password": "supersecret"
@@ -1,5 +1,5 @@
type: object type: object
properties: properties:
accessToken: access_token:
description: Access token for subsequent authorization. description: Access token that can be used to send authenticated requests.
type: string type: string
@@ -3,24 +3,13 @@ post:
summary: User Login (JWT) summary: User Login (JWT)
x-authenticated: false x-authenticated: false
description: >- description: >-
After a successful login, a JWT token is returned for subsequent After a successful login, a JWT token is returned, which can be used to send
authorization. authenticated requests.
parameters: []
requestBody: requestBody:
content: content:
application/json: application/json:
schema: schema:
type: object $ref: ../components/schemas/AdminPostAuthReq.yaml
required:
- email
- password
properties:
email:
type: string
description: The User's email.
password:
type: string
description: The User's password.
x-codegen: x-codegen:
method: getToken method: getToken
x-codeSamples: x-codeSamples:
@@ -1,9 +1,9 @@
import Medusa from "@medusajs/medusa-js" import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
medusa.store.auth.getToken({ medusa.auth.getToken({
email: 'user@example.com', email: 'user@example.com',
password: 'supersecret' password: 'supersecret'
}) })
.then(({ accessToken }) => { .then(({ access_token }) => {
console.log(accessToken); console.log(access_token);
}); });
@@ -1,2 +1,2 @@
curl -X DELETE '{backend_url}/store/auth' \ curl -X DELETE '{backend_url}/store/auth' \
-H 'Cookie: connect.sid={sid}' -H 'Authorization: Bearer {access_token}'
@@ -1,2 +1,2 @@
curl '{backend_url}/store/auth' \ curl '{backend_url}/store/auth' \
-H 'Cookie: connect.sid={sid}' -H 'Authorization: Bearer {access_token}'
@@ -0,0 +1,6 @@
curl -X POST '{backend_url}/store/auth/token' \
-H 'Content-Type: application/json' \
--data-raw '{
"email": "user@example.com",
"password": "supersecret"
}'
@@ -1,2 +1,2 @@
curl '{backend_url}/store/customers/me' \ curl '{backend_url}/store/customers/me' \
-H 'Cookie: connect.sid={sid}' -H 'Authorization: Bearer {access_token}'
@@ -1,5 +1,5 @@
curl -X POST '{backend_url}/store/customers/me' \ curl -X POST '{backend_url}/store/customers/me' \
-H 'Cookie: connect.sid={sid}' \ -H 'Authorization: Bearer {access_token}' \
-H 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
--data-raw '{ --data-raw '{
"first_name": "Laury" "first_name": "Laury"
@@ -1,5 +1,5 @@
curl -X POST '{backend_url}/store/customers/me/addresses' \ curl -X POST '{backend_url}/store/customers/me/addresses' \
-H 'Cookie: connect.sid={sid}' \ -H 'Authorization: Bearer {access_token}' \
-H 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
--data-raw '{ --data-raw '{
"address": { "address": {
@@ -1,2 +1,2 @@
curl -X DELETE '{backend_url}/store/customers/me/addresses/{address_id}' \ curl -X DELETE '{backend_url}/store/customers/me/addresses/{address_id}' \
-H 'Cookie: connect.sid={sid}' -H 'Authorization: Bearer {access_token}'
@@ -1,5 +1,5 @@
curl -X POST '{backend_url}/store/customers/me/addresses/{address_id}' \ curl -X POST '{backend_url}/store/customers/me/addresses/{address_id}' \
-H 'Cookie: connect.sid={sid}' \ -H 'Authorization: Bearer {access_token}' \
-H 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
--data-raw '{ --data-raw '{
"first_name": "Gina" "first_name": "Gina"
@@ -1,2 +1,2 @@
curl '{backend_url}/store/customers/me/orders' \ curl '{backend_url}/store/customers/me/orders' \
-H 'Cookie: connect.sid={sid}' -H 'Authorization: Bearer {access_token}'
@@ -1,2 +1,2 @@
curl '{backend_url}/store/customers/me/payment-methods' \ curl '{backend_url}/store/customers/me/payment-methods' \
-H 'Cookie: connect.sid={sid}' -H 'Authorization: Bearer {access_token}'
@@ -1,6 +0,0 @@
curl --location --request POST 'https://medusa-url.com/store/auth/token' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "user@example.com",
"password": "supersecret"
}'
@@ -1,5 +1,5 @@
type: object type: object
properties: properties:
accessToken: access_token:
description: Access token for subsequent authorization. description: Access token that can be used to send authenticated requests.
type: string type: string
@@ -154,6 +154,8 @@ servers:
paths: paths:
/store/auth: /store/auth:
$ref: paths/store_auth.yaml $ref: paths/store_auth.yaml
/store/auth/token:
$ref: paths/store_auth_token.yaml
/store/auth/{email}: /store/auth/{email}:
$ref: paths/store_auth_{email}.yaml $ref: paths/store_auth_{email}.yaml
/store/carts: /store/carts:
@@ -262,8 +264,6 @@ paths:
$ref: paths/store_swaps.yaml $ref: paths/store_swaps.yaml
/store/swaps/{cart_id}: /store/swaps/{cart_id}:
$ref: paths/store_swaps_{cart_id}.yaml $ref: paths/store_swaps_{cart_id}.yaml
/store/token:
$ref: paths/store_token.yaml
/store/variants: /store/variants:
$ref: paths/store_variants.yaml $ref: paths/store_variants.yaml
/store/variants/{id}: /store/variants/{id}:
@@ -3,35 +3,24 @@ post:
summary: Customer Login (JWT) summary: Customer Login (JWT)
x-authenticated: false x-authenticated: false
description: >- description: >-
After a successful login, a JWT token is returned for subsequent After a successful login, a JWT token is returned, which can be used to send
authorization. authenticated requests.
parameters: []
requestBody: requestBody:
content: content:
application/json: application/json:
schema: schema:
type: object $ref: ../components/schemas/StorePostAuthReq.yaml
required:
- email
- password
properties:
email:
type: string
description: The User's email.
password:
type: string
description: The User's password.
x-codegen: x-codegen:
method: getToken method: getToken
x-codeSamples: x-codeSamples:
- lang: JavaScript - lang: JavaScript
label: JS Client label: JS Client
source: source:
$ref: ../code_samples/JavaScript/store_token/post.js $ref: ../code_samples/JavaScript/store_auth_token/post.js
- lang: Shell - lang: Shell
label: cURL label: cURL
source: source:
$ref: ../code_samples/Shell/store_token/post.sh $ref: ../code_samples/Shell/store_auth_token/post.sh
tags: tags:
- Auth - Auth
responses: responses: