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
|
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:
|
|
Authentication |
Manually authenticate to generate the authorization code. |
None required. The OAuth client contains the necessary credentials and privileges. |
|
Parameters |
|
|
Log in by Passing OAuth Client Information as Options
datasphere login
--client-id "<id>"
--client-secret "<secret>"
--authorization-url "<url>"
--token-url "<url>"
--host "<url>"
--browser "<browser-name>"
--authorization-flow "<flow>"
|
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:
|
|
--authorization-flow "<flow>" |
[optional] Enter the appropriate authorization flow for your OAuth client:
|
Log in by Passing OAuth Client Information in an Options File
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.
datasphere config secrets show
$ 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",
...
}
]
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.
datasphere spaces read --space My_SPACE --secrets-file <secrets-file>.jsonWhere 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.
datasphere login --secrets-file dev-secrets.json --host https://my-datasphere-devThen log into your production SAP Datasphere tenant by entering:
datasphere login --secrets-file prod-secrets.json --host https://my-datasphere-prodYou 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.
datasphere config host set https://my-datasphere-devYou are now connected to the https://my-datasphere-dev tenant, and any commands you enter will be applied to this tenant.
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.
-
openssl s_client -connect <tenant_url>:443 -showcerts -
curl -vI <tenant_url> -
curl --verbose --cacert /etc/ssl/certs/ca-certificates.crt <tenant_url>
-
js process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
-
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-cli
.