OCI SDK Authentication Methods

The OCI SDK and CLI supports the following authentication methods:
  • API key-based authentication
  • Session token-based authentication
  • Instance principal
  • Resource principal

This section discusses each method in detail and provides examples.

API Key-Based Authentication

In this authentication method, you create a configuration file and store it on the local disk. The configuration file contains details such as the user OCID, tenancy OCID, region, private key path, and fingerprint. This authentication method creates a permanent configuration file on your machine. It should be used if you are working from a secure network and are comfortable storing private keys and configuration locally.

Examples

The following section shows examples of API key-based authentication.

Session Token-Based Authentication

Using session-token-based authentication, you create a local configuration file that contains information including the user OCID, tenancy OCID, region, private key path and a temporary session token file path. This method uses this information along with the temporary session token, which expires in an hour (by default). Session token-based authentication can be used when you need quick, temporary authentication.

Examples

The following section shows examples of session token-based authentication.

Instance Principal Authentication

Using instance principal authentication, you can authorize an instance to make API calls on Oracle Cloud Infrastructure services. After you set up the required resources and policies, an application running on an instance can call Oracle Cloud Infrastructure public services, removing the need to configure user credentials or a configuration file. For more details, see instance principal.

Instance principal authentication can be used from an instance or VM where you don't want to store a configuration file.

Examples

The following section shows examples of instance principal authentication.

Resource Principal Authentication

Resource principal authentication is very similar to instance principal authentication, but is intended to be used for resources that are not instances, such as server-less functions.

Examples

The following section shows examples of resource principal authentication.