Files
netbird-docs/docs/api/create-token.api.mdx
2023-04-26 15:06:59 +02:00

54 lines
8.0 KiB
Plaintext

---
id: create-token
title: "Create a Token"
description: "Create a new token for a user"
sidebar_label: "Create a Token"
hide_title: true
hide_table_of_contents: true
api: {"description":"Create a new token for a user","tags":["Tokens"],"operationId":"createToken","security":[{"BearerAuth":[]},{"TokenAuth":[]}],"parameters":[{"in":"path","name":"userId","required":true,"schema":{"type":"string"},"description":"The unique identifier of a user"}],"requestBody":{"description":"PersonalAccessToken create parameters","content":{"application/json":{"schema":{"type":"object","properties":{"name":{"description":"Name of the token","type":"string"},"expires_in":{"description":"Expiration in days","type":"integer","minimum":1,"maximum":365}},"required":["name","expires_in"],"title":"PersonalAccessTokenRequest"}}}},"responses":{"200":{"description":"The token in plain text","content":{"application/json":{"schema":{"type":"object","properties":{"plain_token":{"description":"Plain text representation of the generated token","type":"string"},"personal_access_token":{"type":"object","properties":{"id":{"description":"ID of a token","type":"string"},"name":{"description":"Name of the token","type":"string"},"expiration_date":{"description":"Date the token expires","type":"string","format":"date-time"},"created_by":{"description":"User ID of the user who created the token","type":"string"},"created_at":{"description":"Date the token was created","type":"string","format":"date-time"},"last_used":{"description":"Date the token was last used","type":"string","format":"date-time"}},"required":["id","name","expiration_date","created_by","created_at"],"title":"PersonalAccessToken"}},"required":["plain_token","personal_access_token"],"title":"PersonalAccessTokenGenerated"}}}},"400":{"description":"Bad Request","content":{}},"401":{"description":"Requires authentication","content":{}},"403":{"description":"Forbidden","content":{}},"500":{"description":"Internal Server Error","content":{}}},"method":"post","path":"/api/users/{userId}/tokens","servers":[{"url":"https://netbird.io","description":"Default server"}],"securitySchemes":{"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"},"TokenAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"Prefix the value with \\\"Token\\\" to indicate the custom authorization type"}},"jsonRequestBodyExample":{"name":"string","expires_in":0},"info":{"title":"NetBird REST API","description":"API to manipulate groups, rules, policies and retrieve information about peers and users","version":"0.0.1"},"postman":{"name":"Create a Token","description":{"content":"Create a new token for a user","type":"text/plain"},"url":{"path":["api","users",":userId","tokens"],"host":["{{baseUrl}}"],"query":[],"variable":[{"disabled":false,"description":{"content":"(Required) The unique identifier of a user","type":"text/plain"},"type":"any","value":"","key":"userId"}]},"header":[{"key":"Content-Type","value":"application/json"},{"key":"Accept","value":"application/json"}],"method":"POST","body":{"mode":"raw","raw":"\"\"","options":{"raw":{"language":"json"}}},"auth":{"type":"bearer","bearer":[{"type":"any","value":"<Bearer Token>","key":"token"}]}}}
sidebar_class_name: "post api-method"
info_path: api/netbird-rest-api
custom_edit_url: null
---
import ApiTabs from "@theme/ApiTabs";
import MimeTabs from "@theme/MimeTabs";
import ParamsItem from "@theme/ParamsItem";
import ResponseSamples from "@theme/ResponseSamples";
import SchemaItem from "@theme/SchemaItem";
import SchemaTabs from "@theme/SchemaTabs";
import DiscriminatorTabs from "@theme/DiscriminatorTabs";
import TabItem from "@theme/TabItem";
## Create a Token
Create a new token for a user
<details style={{"marginBottom":"1rem"}} data-collapsed={false} open={true}><summary style={{}}><strong>Path Parameters</strong></summary><div><ul><ParamsItem className={"paramsItem"} param={{"in":"path","name":"userId","required":true,"schema":{"type":"string"},"description":"The unique identifier of a user"}}></ParamsItem></ul></div></details><MimeTabs><TabItem label={"application/json"} value={"application/json-schema"}><details style={{}} data-collapsed={false} open={true}><summary style={{"textAlign":"left"}}><strong>Request Body</strong></summary><div style={{"textAlign":"left","marginLeft":"1rem"}}><div style={{"marginTop":"1rem","marginBottom":"1rem"}}>
PersonalAccessToken create parameters
</div></div><ul style={{"marginLeft":"1rem"}}><SchemaItem collapsible={false} name={"name"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Name of the token","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"expires_in"} required={true} schemaName={"integer"} qualifierMessage={"**Possible values:** `>= 1` and `<= 365`"} schema={{"description":"Expiration in days","type":"integer","minimum":1,"maximum":365}}></SchemaItem></ul></details></TabItem></MimeTabs><div><ApiTabs><TabItem label={"200"} value={"200"}><div>
The token in plain text
</div><div><MimeTabs schemaType={"response"}><TabItem label={"application/json"} value={"application/json"}><SchemaTabs><TabItem label={"Schema"} value={"Schema"}><details style={{}} data-collapsed={false} open={true}><summary style={{"textAlign":"left"}}><strong>Schema</strong></summary><div style={{"textAlign":"left","marginLeft":"1rem"}}></div><ul style={{"marginLeft":"1rem"}}><SchemaItem collapsible={false} name={"plain_token"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Plain text representation of the generated token","type":"string"}}></SchemaItem><SchemaItem collapsible={true} className={"schemaItem"}><details style={{}}><summary style={{}}><strong>personal_access_token</strong><span style={{"opacity":"0.6"}}> object</span><strong style={{"fontSize":"var(--ifm-code-font-size)","color":"var(--openapi-required)"}}> required</strong></summary><div style={{"marginLeft":"1rem"}}><SchemaItem collapsible={false} name={"id"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"ID of a token","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"name"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"Name of the token","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"expiration_date"} required={true} schemaName={"date-time"} qualifierMessage={undefined} schema={{"description":"Date the token expires","type":"string","format":"date-time"}}></SchemaItem><SchemaItem collapsible={false} name={"created_by"} required={true} schemaName={"string"} qualifierMessage={undefined} schema={{"description":"User ID of the user who created the token","type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"created_at"} required={true} schemaName={"date-time"} qualifierMessage={undefined} schema={{"description":"Date the token was created","type":"string","format":"date-time"}}></SchemaItem><SchemaItem collapsible={false} name={"last_used"} required={false} schemaName={"date-time"} qualifierMessage={undefined} schema={{"description":"Date the token was last used","type":"string","format":"date-time"}}></SchemaItem></div></details></SchemaItem></ul></details></TabItem><TabItem label={"Example (from schema)"} value={"Example (from schema)"}><ResponseSamples responseExample={"{\n \"plain_token\": \"string\",\n \"personal_access_token\": {\n \"id\": \"string\",\n \"name\": \"string\",\n \"expiration_date\": \"2023-04-26T12:12:56.621Z\",\n \"created_by\": \"string\",\n \"created_at\": \"2023-04-26T12:12:56.621Z\",\n \"last_used\": \"2023-04-26T12:12:56.621Z\"\n }\n}"} language={"json"}></ResponseSamples></TabItem></SchemaTabs></TabItem></MimeTabs></div></TabItem><TabItem label={"400"} value={"400"}><div>
Bad Request
</div><div></div></TabItem><TabItem label={"401"} value={"401"}><div>
Requires authentication
</div><div></div></TabItem><TabItem label={"403"} value={"403"}><div>
Forbidden
</div><div></div></TabItem><TabItem label={"500"} value={"500"}><div>
Internal Server Error
</div><div></div></TabItem></ApiTabs></div>