Token-based authentication for the CLI allows you to create a temporary session token
which can be used to authenticate a CLI command request. You can generate this token
with or without using a web browser.
Requirements
The requirements are the same as those listed for the CLI in Requirements.
Creating a CLI Session with a Browser 🔗
To use token-based authentication for the CLI on a computer with a web browser:
In the terminal, run the following command:
Copy
oci session authenticate
Select a region.
In the browser, enter your user credentials.
After successful authentication, close the browser and follow interactive prompt on
the terminal. A configuration file will be created.
Creating a CLI Session without a Browser 🔗
To generate a user token without a browser, you must first authenticate with one of the
following methods:
API key based authentication (oci setup config)
Session token based authentication (oci session authenticate)
API key-based authentication
To use token-based authentication for the CLI without a web browser, run the following
command:
Copy
oci session authenticate --no-browser
This command creates a public/private key pair and updates the private key
file location in .config file.
For both the API key-based and session token-based authentication, you can provide a path
to a public key as an argument. This provides a session token which can be signed by
corresponding private key while using the generated token.
You can control the time for which the token persists. The minimum time for which token
persists is 5 minutes and the maximum time for token persistence is 60 minutes (the
default value). To setup a custom session expiration for the token, use the parameter
--session-expiration-in-minutes. For
example:
You should receive a message showing the expiration date for the session. If you receive
an error, check your profile settings.
Note
You must use the --auth
security_token or set the OCI_CLI_AUTH environment
variable to security_token to authenticate CLI commands using the
session token.
Refreshing a Token 🔗
The default token expiration time is set to 1 hour, and can be refreshed within the
validity period up to 24 hours.
Note
For sessions authenticated
using oci session authenticate --no-browser, the maximum value is
60 minutes.
To refresh the token, run the following command:
Copy
oci session refresh --profile <profile_name>
Note
You must use the --auth security_token or set the
OCI_CLI_AUTH environment variable to
security_token to authenticate CLI commands using the session
token.
Copying a CLI Session Token to Another Machine 🔗
To use token-based authentication for the CLI on a computer without a web browser, you must export a session from a web-enabled computer, then import it to the computer without a web browser.
Exporting from Source Computer
On the source computer with the browser:
In the CLI, run the following command:
Copy
oci session authenticate
Enter the user credentials you wish to use on the target computer.