@@ -3,19 +3,18 @@ title: dart pub token
3
3
description : Manage authentication tokens for package repositories.
4
4
---
5
5
6
- _ pub_ _ token_ is one of the subcommands of the [ pub command] ( /tools/pub/cmd ) .
6
+ The ` dart pub token ` subcommand manages a store of secret tokens to
7
+ authenticate against third-party servers when [ publishing] ( pub-lish ) packages
8
+ and [ retrieving] ( pub-get ) dependencies.
7
9
8
- It is used to manage a store of secret tokens for authenticating
9
- against third-party servers when [ publishing] ( pub-lish ) packages and
10
- [ retrieving] ( pub-get ) dependencies.
11
-
12
- The tokens are stored in a
13
- [ user-wide config dir] ( {{site.repo.dart.org}}/cli_util/blob/71ba36e2554f7b7717f3f12b5ddd33751a4e3ddd/lib/cli_util.dart#L88-L118 ) .
10
+ It stores these tokens in a [ user-wide config directory] [ config-dir ] .
14
11
15
12
It has three subcommands: ` add ` , ` list ` and ` remove ` .
16
13
17
- If you try to ` dart pub get ` and have a [ dependency] ( /tools/pub/dependencies ) hosted
18
- on a private repository you _ may_ be asked to provide credentials:
14
+ Consider a scenario when you have a [ dependency] ( /tools/pub/dependencies )
15
+ hosted on a private repository.
16
+ When you invoke ` dart pub get ` , the command _ might_ return a prompt
17
+ to provide credentials:
19
18
20
19
``` console
21
20
$ dart pub get
@@ -26,13 +25,16 @@ https://some-package-repo.com/my-org/my-repo package repository requested authen
26
25
Go to https://some-package-repo.com and log in to obtain your token.
27
26
```
28
27
29
- The last line is a message the server can provide to help you obtaining a token.
30
- Some servers might not provide such a message.
28
+ In this last message, the final line gives you the server that can help you
29
+ obtain a token. Not all servers provide such this message.
30
+
31
+ ## Add a new credential
32
+
33
+ To create a new credential, invoke ` dart pub token add ` .
31
34
32
- ## Adding credentials ` dart pub token add `
35
+ ### Add a credential for the current session
33
36
34
- To enter the credentials use ` dart pub token add ` ,
35
- and type the credential on stdin.
37
+ At the prompt, type the credential on the command line (` stdin ` ).
36
38
37
39
``` console
38
40
$ dart pub token add https://some-package-repo.com/my-org/my-repo
@@ -42,33 +44,45 @@ Enter secret token: <Type token on stdin>
42
44
```
43
45
44
46
::: note
45
- The token is input on stdin rather than as a command line option to avoid it
46
- ending up in the shell history such as ` ~/.bash_history ` .
47
+ The token takes input on ` stdin ` rather than as a command line option
48
+ to keep the token out of the shell history .
47
49
:::
48
50
49
- In a scripting situation you can store the secret in an environment variable and
50
- use ` dart pub token add <hosted-url> --env-var <ENV_VAR_NAME> ` .
51
+ ### Add a credential for all sessions
51
52
52
- ``` console
53
- $ dart pub token add https://other-package-repo.com/ --env-var TOKEN_VAR
54
- Requests to "https://other-package-repo.com/" will now be authenticated using the secret token stored in the environment variable "TOKEN_VAR".
55
- ```
53
+ In a script, you can store the secret in an environment variable.
54
+
55
+ If you choose to store your secret in an environment variable,
56
+ find a way to hide the secret from your shell history.
57
+ To explore one way of doing this, consult [ this post on Medium] [ zsh-post ] .
58
+ If you add a local environment variable, you need to restart any open
59
+ consoles to enable that new variable.
60
+
61
+ Most CI environments can inject secrets into an environment variable.
62
+ To learn how, consult documentation for [ GitHub Actions] [ ]] or
63
+ [ GitLab] [ ] as examples.
56
64
57
- This will cause ` dart pub get ` to read whatever is stored in ` $TOKEN_VAR ` and
58
- use that as the authentication token.
65
+ [ GitHub Actions ] : https://docs.github.com/actions/security-guides/encrypted-secrets#using-encrypted-secrets-in-a-workflow
66
+ [ GitLab ] : https://docs.gitlab.com/ee/ci/secrets/
67
+ [ zsh-post ] : https://medium.com/@prasincs/hiding-secret-keys-from-shell-history-part-1-5875eb5556cc
59
68
60
- You can set the environment variable in Bash with ` export TOKEN_VAR=... ` but
61
- that still doesn't prevent the command being logged.
69
+ To use an environment variable as a token, invoke:
62
70
63
- Most CI environments has a way to inject secrets into an environment
64
- variable:
71
+ ``` console
72
+ dart pub token add <hosted-url> --env-var <ENV_VAR_NAME>
73
+ ```
65
74
66
- * [ GitHub Actions ] ( https://docs.github.com/actions/security-guides/encrypted-secrets#using-encrypted-secrets-in-a-workflow ) .
67
- * [ GitLab ] ( https://docs.gitlab.com/ee/ci/secrets/ ) .
75
+ This causes ` dart pub get ` to read the data stored in ` $TOKEN_VAR ` then
76
+ use it as the authentication token .
68
77
69
- ## Listing credentials ` dart pub token list `
78
+ ``` console
79
+ $ dart pub token add https://other-package-repo.com/ --env-var TOKEN_VAR
80
+ Requests to "https://other-package-repo.com/" will now be authenticated using the secret token stored in the environment variable "TOKEN_VAR".
81
+ ```
82
+
83
+ ## Return a list of credentials
70
84
71
- To see a list of all active credentials use ` dart pub token list ` :
85
+ To see a list of all active credentials, invoke ` dart pub token list ` :
72
86
73
87
``` console
74
88
$ dart pub token list
@@ -77,22 +91,23 @@ https://some-package-repo.com/my-org/my-repo
77
91
https://other-package-repo.com/
78
92
```
79
93
80
- ## Removing credentials ` dart pub token remove `
94
+ ## Remove one or more credentials
81
95
82
- You can remove a single token with ` dart pub token remove ` :
96
+ To remove a single token, invoke ` dart pub token remove ` :
83
97
84
98
``` console
85
99
$ dart pub token remove https://other-package-repo.com
86
100
Removed secret token for package repository: https://other-package-repo.com
87
101
```
88
102
89
- Or remove all with ` remove --all ` :
103
+ To remove all tokens, invoke the command with the ` remove --all ` option :
90
104
91
105
``` console
92
106
$ dart pub token remove --all
93
107
pub-tokens.json is deleted.
94
108
Removed 1 secret tokens.
95
109
```
96
110
97
-
98
111
{% include 'pub-problems.md' %}
112
+
113
+ [ config-dir ] : {{site.repo.dart.org}}/cli_util/blob/71ba36e2554f7b7717f3f12b5ddd33751a4e3ddd/lib/cli_util.dart#L88-L118
0 commit comments