Token
Definition
- JSON
- Typescript
token.json
{
"id": 0,
"userID": 0,
"accessToken": "",
"refreshToken": "",
"scope": "",
"code": "",
"codeChallenge": "",
"tokenType": "",
"expireAt": "",
"client": "",
"version": "",
"createdAt": "",
"updatedAt": "",
}
token.ts
export interface IToken {
id: number;
userID: number;
accessToken: string;
refreshToken: string;
scope: string;
code: string;
codeChallenge: string | null;
tokenType: string;
expireAt: Date | null;
client: string;
version: string;
createdAt: Date | null;
updatedAt: Date | null;
}
Get Tokens
- Curl
- Typescript
curl -X GET "${baseUrl}/token/?filter=${filter}&orderBy=${orderBy}&page=${page}&pageSize=${pageSize}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
const response = await fetch("${baseUrl}/token/?filter=${filter}&orderBy=${orderBy}&page=${page}&pageSize=${pageSize}", {
method: "GET",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}
Get Token
- Curl
- Typescript
curl -X GET "${baseUrl}/token/${id}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
const response = await fetch("${baseUrl}/token/${id}", {
method: "GET",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}
Apply Token.ID
- Curl
- Typescript
curl -X POST "${baseUrl}/apply/token/id/" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
const response = await fetch("${baseUrl}/apply/token/id/", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
body: JSON.stringify(payload),
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}
Create Token
- Curl
- Typescript
curl -X POST "${baseUrl}/token/" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d @token.json
info
token.json
{
"userID": 0,
"accessToken": "",
"refreshToken": "",
"scope": "",
"code": "",
"codeChallenge": "",
"tokenType": "",
"expireAt": "",
}
tip
success status: 201
const response = await fetch("${baseUrl}/token/", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
body: JSON.stringify(payload),
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}
Update Token
- Curl
- Typescript
#!/bin/bash
curl -X PUT "${baseUrl}/token/${id}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d @token.json
info
token.json
{
"userID": 0,
"accessToken": "",
"refreshToken": "",
"scope": "",
"code": "",
"codeChallenge": "",
"tokenType": "",
"expireAt": "",
}
const response = await fetch("${baseUrl}/token/${id}", {
method: "PUT",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
body: JSON.stringify(payload),
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}
Patch Token
- Curl
- Typescript
curl -X PATCH "${baseUrl}/token/${id}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Attrs: userID,accessToken,refreshToken,scope,code,codeChallenge,tokenType,expireAt" \
-d @token.json
info
token.json
{
"userID": 0,
"accessToken": "",
"refreshToken": "",
"scope": "",
"code": "",
"codeChallenge": "",
"tokenType": "",
"expireAt": "",
}
const response = await fetch("${baseUrl}/token/${id}", {
method: "PATCH",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
"Attrs": "${attrs}",
},
body: JSON.stringify(payload),
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}
Destroy Token
- Curl
- Typescript
curl -X DELETE "${baseUrl}/token/${id}" \
-H "Authorization: Bearer ${accessToken}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
const response = await fetch("${baseUrl}/token/${id}", {
method: "DELETE",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
})
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}