mirror of
https://github.com/coder/coder.git
synced 2026-10-25 09:42:55 +08:00
feat(cli): add 'coder login token' command to print session token (#21627)
Adds a new subcommand to print the current session token for use in scripts and automation, similar to `gh auth token`. ## Usage ```bash CODER_SESSION_TOKEN=$(coder login token) ``` Fixes #21515
This commit is contained in:
@@ -9,6 +9,21 @@ The [Coder CLI](../../install/cli.md) and
|
||||
token to authenticate. To generate a short-lived session token on behalf of your
|
||||
account, visit the following URL: `https://coder.example.com/cli-auth`
|
||||
|
||||
### Retrieve the current session token
|
||||
|
||||
If you're already logged in with the CLI, you can retrieve your current session
|
||||
token for use in scripts and automation:
|
||||
|
||||
```sh
|
||||
coder login token
|
||||
```
|
||||
|
||||
This is useful for passing your session token to other tools:
|
||||
|
||||
```sh
|
||||
export CODER_SESSION_TOKEN=$(coder login token)
|
||||
```
|
||||
|
||||
### Session Durations
|
||||
|
||||
By default, sessions last 24 hours and are automatically refreshed. You can
|
||||
|
||||
@@ -22,6 +22,16 @@ Instead of distributing provider-specific API keys (OpenAI/Anthropic keys) to us
|
||||
|
||||
Again, the exact environment variable or setting naming may differ from tool to tool; consult your tool's documentation.
|
||||
|
||||
### Retrieving your session token
|
||||
|
||||
If you're logged in with the Coder CLI, you can retrieve your current session
|
||||
token using [`coder login token`](../../reference/cli/login_token.md):
|
||||
|
||||
```sh
|
||||
export ANTHROPIC_API_KEY=$(coder login token)
|
||||
export ANTHROPIC_BASE_URL="https://coder.example.com/api/v2/aibridge/anthropic"
|
||||
```
|
||||
|
||||
## Configuring In-Workspace Tools
|
||||
|
||||
AI coding tools running inside a Coder workspace, such as IDE extensions, can be configured to use AI Bridge.
|
||||
|
||||
@@ -1487,6 +1487,11 @@
|
||||
"description": "Authenticate with Coder deployment",
|
||||
"path": "reference/cli/login.md"
|
||||
},
|
||||
{
|
||||
"title": "login token",
|
||||
"description": "Print the current session token",
|
||||
"path": "reference/cli/login_token.md"
|
||||
},
|
||||
{
|
||||
"title": "logout",
|
||||
"description": "Unauthenticate your local session",
|
||||
|
||||
Generated
+6
@@ -15,6 +15,12 @@ coder login [flags] [<url>]
|
||||
By default, the session token is stored in the operating system keyring on macOS and Windows and a plain text file on Linux. Use the --use-keyring flag or CODER_USE_KEYRING environment variable to change the storage mechanism.
|
||||
```
|
||||
|
||||
## Subcommands
|
||||
|
||||
| Name | Purpose |
|
||||
|----------------------------------------|---------------------------------|
|
||||
| [<code>token</code>](./login_token.md) | Print the current session token |
|
||||
|
||||
## Options
|
||||
|
||||
### --first-user-email
|
||||
|
||||
Generated
+16
@@ -0,0 +1,16 @@
|
||||
<!-- DO NOT EDIT | GENERATED CONTENT -->
|
||||
# login token
|
||||
|
||||
Print the current session token
|
||||
|
||||
## Usage
|
||||
|
||||
```console
|
||||
coder login token
|
||||
```
|
||||
|
||||
## Description
|
||||
|
||||
```console
|
||||
Print the session token for use in scripts and automation.
|
||||
```
|
||||
Reference in New Issue
Block a user