Introduction
Once you have configured your Pub repositories in JFrog Artifactory, you will need to authenticate your Pub client with Artifactory. For this, you will use the dart pub token add command.
Authenticating to Artifactory using Dart client for Pub packages :
The dart pub token subcommand manages a store of tokens. When publishing packages and retrieving dependencies, the dart pub command uses these tokens to authenticate against external sources such as JFrog Artifactory. The tokens are stored in a user-wide config directory. The dart pub token subcommand has three options: add, list, and remove.
To create a new credential, use the dart pub token add command. At the prompt, type the credential on the command line (stdin):
dart pub token add <hosted-url>
For example :
dart pub token add "https://test.frog.com/artifactory/api/pub/test-pub"
Enter secret token: (Type your token on stdin)
Requests to "https://test.frog.com/artifactory/api/pub/test-pub " will now be authenticated using the secret token.
However, this method is short-lived, and the token will only be available for the current session.
If you would like to use the same token for any and all terminal sessions and in scripts, store the token in an environment variable.
Using Environment Variables for Tokens
To use an environment variable as a token, use the following command:
dart pub token add <hosted-url> --env-var <TOKEN_VAR>
For example :
dart pub token add "https://test.frog.com/artifactory/api/pub/test-pub" --env-var JFROG_PUB_TOKEN
Requests to "https://test.frog.com/artifactory/api/pub/test-pub" will now be authenticated using the secret token stored in the environment variable JFROG_PUB_TOKEN.
This approach is particularly helpful if you are using Pub packages with JFrog Artifactory in your CI/CD environments, as most CI environments can inject tokens into an environment variable, making them available for all sessions.
Also, you can use the following command to see a list of all active credentials in your Dart client.
dart pub token list
You have secret tokens for 2 package repositories:
https://test1.frog.com/artifactory/api/pub/test1-pub
https://test2.frog.com/artifactory/api/pub/test2-pub