Log into the Command Line Interface via an OAuth Client

If an administrator has created an OAuth client (with Purpose set to Interactive Usage or Technical User) for datasphere command line interface users to log into, there are several methods for accessing it.

Prerequisites

To connect to SAP Datasphere via the datasphere command line interface, you must have a global or scoped role granting necessary privileges for the commands you want to use and access to the appropriate spaces. You must, in addition obtain access to an appropriate OAuth client:

OAuth Purpose

Interactive Usage

Technical User

Authorization Grant

Authorization Code

Three- Legged (User-Client-Server): Manually propagate authorization to another service.

Client Credentials

Two-Legged (Client-Server): Service to service communication via APIs.

Supported for the following commands only:
  • datasphere configuration certificates

  • datasphere marketplace

  • datasphere objects

  • datasphere spaces connections

  • datasphere tasks

Authentication

Manually authenticate to generate the authorization code.

None required. The OAuth client contains the necessary credentials and privileges.

Parameters

  • Client ID

  • Secret

  • Authorization URL

  • Token URL

  • Client ID

  • Secret

  • Token URL

For more information, see Create OAuth2.0 Clients to Authenticate Against SAP Datasphere.

Log in by Passing OAuth Client Information as Options

You can log in by passing the OAuth client information as options on the command line. To log in, enter the following command and press Return:
datasphere login 
    --client-id "<id>" 
    --client-secret "<secret>" 
    --authorization-url "<url>"
    --token-url "<url>"
    --host "<url>" 
    --browser "<browser-name>"
    --authorization-flow "<flow>"
    
Complete the parameters as follows:

Parameter

Description

--client-id "<id>"

Enter the OAuth Client ID provided by your administrator.

--client-secret "<secret>"

Enter the Secret provided by your administrator.

--authorization-url "<url>"

[optional] Enter the Authorization URL provided by your administrator.

--token-url "<url>"

[optional] Enter the Token URL provided by your administrator.

--host "<url>"

Enter the URL of your SAP Datasphere tenant. You can copy the URL of any page in your tenant. Alternatively, set a host value (see Set a Host Value to Identify Your SAP Datasphere Tenant).

--browser "<browser-name>"

[optional] Enter your <browser-name>, if you are not using Google Chrome, from among the following, to specify which browser to open to obtain privileges and space permissions:

  • chrome (default)

  • edge

  • firefox

  • brave

  • safari

--authorization-flow "<flow>"

[optional] Enter the appropriate authorization flow for your OAuth client:

Log in by Passing OAuth Client Information in an Options File

You can log in more securely by passing the OAuth client information in an options file instead of on the command line. To log in, enter the following command and press Return:
datasphere login 
    --options-file <file>.json
Complete the parameters as follows:

Parameter

Description

--options-file <file>.json

Enter a path to a .json file containing the basic OAuth and other login options:

{
    "client-id": "<client-id>",
    "client-secret": "<client-secret>",
    "authorization-url": "<authorization-url>",
    "token-url": "<token-url>",
    "host": "<url>",
    "browser": "<browser-name>",
	"authorization-flow": "<flow>"
  }

Run Commands Without a Login by Passing Tokens in a Secrets File

You can avoid running a login command (and entering your SAP Datasphere username and password) at the beginning of each OAuth session by extracting the personal access and refresh tokens and passing them either as options or in a secrets file.

To extract your tokens, log into datasphere as usual, and then enter the following command and press Return:
datasphere config secrets show
Example output:
$ datasphere config secrets show
[
{
"id": 0,
"client_id": "sb-0d85e619...",
"client_secret": "1dcc0522-...",
"tenantUrl": "https://somehost.eu10.cloud.sap",
...
},
{
"id": 1,
"client_id": "sb-0d85e619...",
"client_secret": "1dcc0522-...",
"tenantUrl": "https://somehost.us10.cloud.sap",
...
}
]					
				
Then copy the values for access_token and refresh_token. You can pass these values either as options on the command line or in a secrets file.

Having extracted your tokens, you no longer need to log in at the beginning of your session and can pass your tokens in a secrets file with any command.

For example, the following command, to read a space, can be run without having logged in beforehand:
datasphere spaces read --space My_SPACE --secrets-file <secrets-file>.json
Where the <secrets-file>.json contains the following options:
{
    "client_id": "<client-id>",
    "client_secret": "<client-secret>",
    "authorization_url": "<authorization-url>",
    "token_url": "<token-url>",
    "access_token": "<access-token>",
    "refresh_token": "<refresh-token>"},
    "host": "<url>",
    "browser": "<browser-name>",
    "authorization_flow": "<flow>"
                                              }

Log Into and Switch Between Multiple SAP Datasphere Tenants

You can log into multiple SAP Datasphere tenants one after the other and then switch between them by changing the --host option as necessary.

For example, you can log into your development SAP Datasphere tenant by entering:
datasphere login --secrets-file dev-secrets.json --host https://my-datasphere-dev
Then log into your production SAP Datasphere tenant by entering:
datasphere login --secrets-file prod-secrets.json --host https://my-datasphere-prod
You are now logged into both the dev and prod tenants, but currently connected to the https://my-datasphere-prod and any commands you enter will be applied to this tenant.
To connect to the development tenant, enter:
datasphere config host set https://my-datasphere-dev
You are now connected to the https://my-datasphere-dev tenant, and any commands you enter will be applied to this tenant.
If at any point you are unsure which tenant you are currently connected to, you can enter:
datasphere config host show

Log Out from the Command Line Interface via an Oauth Client

To log out from an account, use the datasphere logout command: this command allows you to optionally specify the ID of the login/secrets to remove using the option --login-id <id>.

To log out, enter the following command and press Return:

datasphere logout 
--login-id <id>  
			

By default, when you omit the option --login-id <id> the login/secrets with ID 0 are removed.

Parameter

Description

--login-id <id>

Optional: specifies the login ID (choices: "0", default: "0").

Troubleshoot Login Issues

You might encounter login issues when accessing SAP Datasphere via the command line, even though you are able to log into your tenant via your Web browser.

This is commonly due to missing, expired or otherwise invalid certificates in your Node.js trust store.

To debug certificate issues, you can use the following OpenSSL or curl commands:
  • openssl s_client -connect <tenant_url>:443 -showcerts
                        
  • curl -vI <tenant_url>
                        
  • curl --verbose --cacert /etc/ssl/certs/ca-certificates.crt <tenant_url>
                        
To temporarily disable certificate validation use:
  • js process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
Common fixes for these issues include:
  • Add your company’s CA certificate (or other missing or expired certificates) to your Node.js trust store.

  • Contact your administrator to see if other proxy methods are available in your environment.

For further information, see the following blog: FAQ and Troubleshooting Guide for @sap/datasphere-cliInformation published on SAP site.