|
| 1 | +--- |
| 2 | +title: create |
| 3 | +--- |
| 4 | +# Sec-Tokens Create |
| 5 | + |
| 6 | +Create a new security token. |
| 7 | + |
| 8 | +## Usage |
| 9 | + |
| 10 | +``` |
| 11 | +s10k sec-tokens create [-r] -t=<tokenType> [-n=<name>] |
| 12 | + [-D=<description>] [-node=nodeId[,nodeId...]]... |
| 13 | + [-source=sourceId[,sourceId...]]... |
| 14 | + [-N=metaPath[,metaPath...]]... |
| 15 | + [-U=metaPath[,metaPath...]]... |
| 16 | + [-A=path[,path...]]... |
| 17 | + [-exp=<expirationDate>] [-tz=<zone>] |
| 18 | + [-mode=<displayMode>] |
| 19 | + [-agg=aggregation | |
| 20 | + --aggregation=aggregation[,aggregation...]...] |
| 21 | + [-loc=precision | |
| 22 | + --location-precision=precision[,precision...]...] |
| 23 | +``` |
| 24 | + |
| 25 | +## Options |
| 26 | + |
| 27 | +<div markdown="1" class="options-explicit-col-widths"> |
| 28 | + |
| 29 | +| Option | Long Version | Description | |
| 30 | +|:-------|:-------------|:------------| |
| 31 | +| `-A=` | `--api-path=` | an API path(s) to restrict access to ([wildcard patterns][wildcard-pats] allowed) | |
| 32 | +| `-agg=` | `--min-aggregation=` | a minimum [aggregation][aggregation] to restrict access to | |
| 33 | +| | `--aggregation=` | an [aggregation][aggregation] to restrict access to | |
| 34 | +| `-D=` | `--description=` | a description for the token | |
| 35 | +| `-exp=` | `--expiration-date=` | an expiration date for the token,like `2020-10-30` or `2020-10-30T12:45` | |
| 36 | +| `-loc=` | `--min-location-precision=` | a minimum location precision to restrict access to | |
| 37 | +| | `--location-precision=` | a location precision to restrict access to | |
| 38 | +| `-n=` | `--name=` | a brief name for the token | |
| 39 | +| `-N=` | `--node-metadata-path=` | node [metadata paths][metadata-paths] to restrict access to ([wildcard patterns][wildcard-pats] allowed) | |
| 40 | +| `-node=` | `--node-id=` | node ID(s) to restrict access to | |
| 41 | +| `-r` | `--refresh-allowed` | allow signing keys for the token to be refreshed | |
| 42 | +| `-source=` | `--source-id=` | source ID(s) to restrict access to | |
| 43 | +| `-t=` | `--type=` | the type of token to create, one of `ReadNodeData` or `User` | |
| 44 | +| `-tz=` | `--time-zone=` | a time zone ID to treat expiration date as instead of the local time zone, like `Pacific/Auckland` or `-05:00` or `UTC` | |
| 45 | +| `-U=` | `--user-metadata-path=` | user [metadata paths][metadata-paths] to restrict access to ([wildcard patterns][wildcard-pats] allowed) | |
| 46 | +| `-mode=` | `--display-mode=` | the format to display the data as, one of `CSV`, `JSON`, or `PRETTY`; defaults to `PRETTY` | |
| 47 | + |
| 48 | + |
| 49 | +</div> |
| 50 | + |
| 51 | +## Output |
| 52 | + |
| 53 | +The new security token, with its associated secret. |
| 54 | + |
| 55 | +!!! warning |
| 56 | + |
| 57 | + You must copy the **token secret** to a safe place, as SolarNetwork will not show you its value |
| 58 | + ever again. |
| 59 | + |
| 60 | +## Examples |
| 61 | + |
| 62 | +Create a basic `ReadNodeData` token with no policy restrictions: |
| 63 | + |
| 64 | +=== "Create basic token" |
| 65 | + |
| 66 | + ```sh |
| 67 | + s10k sec-tokens create --type ReadNodeData |
| 68 | + ``` |
| 69 | + |
| 70 | +=== "Pretty Output" |
| 71 | + |
| 72 | + ``` |
| 73 | + +----------------------+---------------------------+--------------------------------+---------+--------------+------+-------------+--------+ |
| 74 | + | Token ID | Token Secret | Created | User ID | Type | Name | Description | Policy | |
| 75 | + +----------------------+---------------------------+--------------------------------+---------+--------------+------+-------------+--------+ |
| 76 | + | ZCv5FUjlTlIQGjigLhSW | i.3R5qMQ-4sKg8uUV0XoxBY5y | 2025-09-29T03:51:32.388051375Z | 123 | ReadNodeData | | | | |
| 77 | + +----------------------+---------------------------+--------------------------------+---------+--------------+------+-------------+--------+ |
| 78 | + ``` |
| 79 | + |
| 80 | +=== "CSV Output" |
| 81 | + |
| 82 | + ```csv |
| 83 | + Token ID,Token Secret,Created,User ID,Type,Name,Description,Policy |
| 84 | + Lqc8Z_KzpD8.L0_em0Au,QlmQCrZaemdXmUNISggGF7ed,2025-09-29T03:52:13.248686631Z,123,ReadNodeData,,, |
| 85 | + ``` |
| 86 | + |
| 87 | +=== "JSON Output" |
| 88 | + |
| 89 | + ```json |
| 90 | + { |
| 91 | + "id" : "WoRxAChcFZ.x7s2zT5Y6", |
| 92 | + "authSecret" : "zcqVddxS0YTr6rzAtSA.Wq.x0tRzZL", |
| 93 | + "created" : "2025-09-29 04:13:52.673034405Z", |
| 94 | + "userId" : 123, |
| 95 | + "status" : "Active", |
| 96 | + "type" : "ReadNodeData", |
| 97 | + "expired" : false |
| 98 | + } |
| 99 | + ``` |
| 100 | + |
| 101 | +Create a `User` token with a name, description, and various policy restrictions: |
| 102 | + |
| 103 | +=== "Create token with policy" |
| 104 | + |
| 105 | + ```sh |
| 106 | + s10k sec-tokens create --type User --name 'Reporting: region 1' \ |
| 107 | + --description 'Allow access to region 1 for reporting team.' \ |
| 108 | + --node-id 100,101 --source-id '/REGION1/**' \ |
| 109 | + --min-aggregation Hour \ |
| 110 | + --refresh-allowed |
| 111 | + ``` |
| 112 | + |
| 113 | +=== "Pretty Output" |
| 114 | + |
| 115 | + ``` |
| 116 | + +----------------------+----------------------------+--------------------------------+---------+------+---------------------+----------------------------------------------+------------------------------------+ |
| 117 | + | Token ID | Token Secret | Created | User ID | Type | Name | Description | Policy | |
| 118 | + +----------------------+----------------------------+--------------------------------+---------+------+---------------------+----------------------------------------------+------------------------------------+ |
| 119 | + | kF67p6g30eUXQICUgzQf | PDX3VpOKmrc58HOOqUOv3HTmv0 | 2025-09-29T04:23:20.302916611Z | 123 | User | Reporting: region 1 | Allow access to region 1 for reporting team. | { | |
| 120 | + | | | | | | | | "nodeIds" : [ 100, 101 ], | |
| 121 | + | | | | | | | | "sourceIds" : [ "/REGION1/**" ], | |
| 122 | + | | | | | | | | "minAggregation" : "Hour", | |
| 123 | + | | | | | | | | "refreshAllowed" : true | |
| 124 | + | | | | | | | | } | |
| 125 | + +----------------------+----------------------------+--------------------------------+---------+------+---------------------+----------------------------------------------+------------------------------------+ |
| 126 | + ``` |
| 127 | + |
| 128 | +=== "CSV Output" |
| 129 | + |
| 130 | + ```csv |
| 131 | + Token ID,Token Secret,Created,User ID,Type,Name,Description,Policy |
| 132 | + vWLOCdFTaB8IeF6__bl5,HQyeON_XND0YgkYlMHGz.7qPoYlP,2025-09-29T04:25:03.335116516Z,123,User,Reporting: region 1,Allow access to region 1 for reporting team.,"{ |
| 133 | + ""nodeIds"" : [ 100, 101 ], |
| 134 | + ""sourceIds"" : [ ""/REGION1/**"" ], |
| 135 | + ""minAggregation"" : ""Hour"", |
| 136 | + ""refreshAllowed"" : true |
| 137 | + }" |
| 138 | + ``` |
| 139 | + |
| 140 | +=== "JSON Output" |
| 141 | + |
| 142 | + ```json |
| 143 | + { |
| 144 | + "id" : "0a.vDUsIQFDM.pOShkqf", |
| 145 | + "authSecret" : "mvBMxQukn1TsvmyjxQb6lWEZyebUWp", |
| 146 | + "created" : "2025-09-29 04:25:43.884356539Z", |
| 147 | + "userId" : 123, |
| 148 | + "name" : "Reporting: region 1", |
| 149 | + "description" : "Allow access to region 1 for reporting team.", |
| 150 | + "status" : "Active", |
| 151 | + "type" : "User", |
| 152 | + "expired" : false, |
| 153 | + "policy" : { |
| 154 | + "nodeIds" : [ 100, 101 ], |
| 155 | + "sourceIds" : [ "/REGION1/**" ], |
| 156 | + "minAggregation" : "Hour", |
| 157 | + "refreshAllowed" : true |
| 158 | + } |
| 159 | + } |
| 160 | + ``` |
| 161 | + |
| 162 | + |
| 163 | +[aggregation]: https://github.com/SolarNetwork/solarnetwork/wiki/SolarQuery-API-enumerated-types#aggregation-types |
| 164 | +[metadata-paths]: https://github.com/SolarNetwork/solarnetwork/wiki/SolarNet-API-global-objects#metadata-filter-key-paths |
| 165 | +[wildcard-pats]: https://github.com/SolarNetwork/solarnetwork/wiki/SolarNet-API-global-objects#wildcard-patterns |
0 commit comments