Deno supports sending bearer tokens when requesting a remote module. Bearer tokens are the predominant type of access token used with OAuth 2.0 and is broadly supported by hosting services (e.g. GitHub, Gitlab, BitBucket, Cloudsmith, etc.).
The Deno CLI will look for an environment variable named to
determine what authentication tokens it should consider using when requesting
remote modules. The value of the environment variable is in the format of a n
number of tokens deliminated by a semi-colon (;
) where each token is either:
For example a single token for would look something like this:
And multiple tokens would look like this:
When Deno goes to fetch a remote module, where the hostname matches the hostname
of the remote module, Deno will set the Authorization
header of the request to
the value of Bearer {token}
or . This allows the
remote server to recognize that the request is an authorized request tied to a
specific authenticated user, and provide access to the appropriate resources and
modules on the server.
GitHub
To be able to access private repositories on GitHub, you would need to issue yourself a personal access token. You do this by logging into GitHub and going under Settings -> Developer settings -> Personal access tokens:
You would then choose to Generate new token and give your token a description and appropriate access:
And once created GitHub will display the new token a single time, the value of which you would want to use in the environment variable:
In order to access modules that are contained in a private repository on GitHub,
you would want to use the generated token in the DENO_AUTH_TOKENS
environment
variable scoped to the raw.githubusercontent.com
hostname. For example:
This should allow Deno to access any modules that the user who the token was issued for has access to.
When the token is incorrect, or the user does not have access to the module, GitHub will issue a status, instead of an unauthorized status. So if you are getting errors that the modules you are trying to access are not found on the command line, check the environment variable settings and the personal access token settings.