Setting Up Authentication

You must set up authentication before you can use the SAP Analytics Cloud REST APIs.

The following options are supported for authenticating against the OAuth service:

Authentication Method

Description

Configuring OAuth 2.0 SAML Bearer Assertion Workflow (2-legged OAuth)

For when your application is deployed on a SAP Business Technology Platform (SAP BTP) server and uses the SAP BTP SDK.

Configuring OAuth 2.0 Client Credentials Grant workflow (2-legged OAuth)

For non-browser based application access to the REST API technical user.

Configuring OAuth 2.0 Authorization Code Grant workflow (3-legged OAuth)

For non-browser based application access to the REST API.

Basic Authentication Against the Token Service

The simplest option for getting started for development and automation purposes. Recommended for use with the api/v1/scim endpoint.

You must create an OAuth client in your SAP Analytics Cloud tenant. Your application will then be able to authenticate against the system’s OAuth service and obtain authorization to authenticate against the API.

Configuring OAuth 2.0 SAML Bearer Assertion Workflow (2-legged OAuth)

The OAuth 2.0 SAML Bearer Assertion workflow, is supported for server access to the REST API when your application is deployed on a SAP Business Technology Platform (SAP BTP) server and uses the SAP BTP SDK.

The SAP BTP provides an OAuth2SAMLBearerAssertion destination feature which takes care of the OAuth workflow for you.

Prerequisites

  • SAP Analytics Cloud tenant.

  • An administrator account on an SAP Analytics Cloud tenant.

  • A SAP BTP account for deploying the application used to access the API.

  • Java application to access the API using the SAP BTP SDK.

  • The SAP BTP account hosting the Java application must be configured to use the same IdP as the tenant.

  • You must have a signing certificate for the local service provider for the SAP BTP account hosting the Java application.

Tenant Configuration

To establish a connection, you must configure the following information on your SAP Analytics Cloud tenant:
  • OAuth Client

  • Trusted Identity Provider

For information on registering an OAuth client and Trusted Identity provider, see Managing OAuth Clients and Trusted Identity Providers.
The following OAuth client settings are required:
  • Name

  • OAuth Client ID

  • Authorization Grant

  • Confidential

  • Secret

If the SAP BTP account where your Java application is deployed is not configured to use the same IdP as the SAP Analytics Cloud tenant, see Configure Trust to the SAML Identity Provider Providers.

The signing certificate from the SAP BTP account where your Java application is deployed must be saved on the tenant as a Trusted Identity Provider. The signing certificate can be found in the SAP BTP account in the following location: Start of the navigation pathSCP Cockpit Next navigation step Security Next navigation step Trust Next navigation step Local Service ProviderEnd of the navigation path.

The Local Provider Settings should be set as follows: Configuration Type should be set to Custom, Principle Propagation must be set to Enabled, and Generate Key Pair if Required must be selected. For additional details, see Configure SAP Business Technology Platform as a Local Service Provider Providers. Copy the produced Signing Certificate and save it as a Trusted Identity provider on the tenant. For more information, see Managing OAuth Clients and Trusted Identity Providers.

Application Configuration

To configure your application you must:
  1. Deploy your application to your SAP BTP account.

  2. Configure a destination with the Authentication Type OAuth2SAMLBearerAssertion in the SAP BTP account to connect your application to the API end point.

The OAuth2SAMLBearerAssertion destination will need to be configured to match the OAuth Client settings saved in the tenant. For details on how to configure the destination, see SAML Bearer Assertion Authentication. The following fields in the destination will need to be populated with tenant specific values:
  • Audience

  • Client Key

  • Token Service

  • Token Service User

  • Token Service Password

The Audience field should be set to the URL of the tenant being accessed. Token Service should be set to the Token URL that is listed on the SAP Analytics Cloud Start of the navigation pathSystem Next navigation step Administration Next navigation step OAuth ClientsEnd of the navigation path page. The Client Key and Token Service User use the Client ID set in the OAuth Client saved on your SAP Analytics Cloud tenant. The Token Service Password is the Secret saved in the SAP Analytics Cloud tenant.

Once the tenant is configured and the destination in the SAP BTP account is configured, your application may attempt to complete the workflow. We recommend using the SAP BTP SDK to access the destination from within your application as it simplifies the OAuth workflow. For more information on how to use the SAP BTP SDK to access destinations, see these Tutorials.

Configuring OAuth 2.0 Authorization Code Grant Workflow (3-legged OAuth)

The OAuth 2.0 Authorization Code Grant workflow, is supported in SAP Analytics Cloud for non-browser based application access to the REST API.

As part of the OAuth 2.0 Authorization Code Grant workflow, the application consuming the SAP Analytics Cloud endpoint must obtain an authorization token from the SAP Analytics Cloud tenant in order to access resources.

Prerequisites

  • SAP Analytics Cloud tenant.

  • An administrator account on the SAP Analytics Cloud tenant.

  • A non-browser based application used to access the REST API.

Tenant Configuration

To establish a connection, an OAuth Client must be registered on your SAP Analytics Cloud tenant. For information on registering an OAuth client, see Managing OAuth Clients and Trusted Identity Providers.

The following OAuth client settings are required in the New OAuth Client dialog:
  • Name

  • OAuth Client ID

  • Authorization Grant - The type must be set to Authorization Code

  • Confidential

  • Secret

Once the OAuth Client is registered on your SAP Analytics Cloud tenant, your application may attempt to complete the OAuth workflow to access the API resources. You will need the OAuth Client ID and Secret, to configure your application.

Application Configuration

The application will need to obtain an Access Token from the SAP Analytics Cloud tenant in order to access the API resources for a user. The Token URL and Authorization URL are required to complete the workflow. The URLs are listed on the SAP Analytics Cloud Start of the navigation pathSystem Next navigation step Administration Next navigation step OAuth ClientsEnd of the navigation path page.

The application will need to:
  1. Request Authorization Code.

    1. This must be done through the tenant Authorization URL.

    2. The user must enter their SAP Analytics Cloud tenant credentials when redirected to the tenant IdP.

    3. Access to the requested resources must be authorized by the user when prompted.

  2. Request Access Token.

    1. This must be done via the tenant Token URL.

    2. The Authorization Code from step 1 is required.

    3. The OAuth Client ID and Secret and must be provided as part of the request.

  3. If OAuth authorization is successful, the returned token can be used to access the API.

Basic Authentication Against the Token Service

You must create an OAuth client in your SAP Analytics Cloud tenant. Your application will then be able to authenticate against the system’s OAuth service and obtain authorization to authenticate against the API.

Prerequisites

An OAuth client for your application must be created in SAP Analytics Cloud. For more information, see Managing OAuth Clients and Trusted Identity Providers.

Context

The exact mechanism for authenticating against the token service will depend upon the programming language you are using and whether you are using a framework for managing OAuth requests. In general, you must do the following:

Procedure

  1. Obtain an OAuth access token by sending an HTTP POST request to your system's token URL.

    You must include the URL parameter: ?grant_type=client_credentials. You must also include the following HTTP header: Authorization: Basic Base64-encoding-of-<OAuthClientID>:<Secret>, where <OAuthClientID> is the OAuth Client ID you set when you created the client in SAP Analytics Cloud and <Secret> is the secret value.

  2. Retrieve the value of the Access_Token from the JSON response.

    You must pass this access_token as a bearer token in the Authorization header of all requests that you make to the API.

  3. Set up a cookie store to maintain session while operating against the API.
  4. Obtain an x-csrf-token by issuing a GET request to one of the API endpoints.

    Example endpoint: https://<tenant-name>.<region>.sapanalytics.cloud/api/v1/scim/Groups

    You must include the following headers with your GET request:
    • Authorization: Bearer <Access_Token>

    • x-sap-sac-custom-auth: true

    • x-csrf-token: fetch

    For a direct API domain, the tokens x-sap-sac-custom-auth and x-csrf-token can be omitted from the endpoint.

    Example endpoint: https://<tenant-name>.api.<region>.sapanalytics.cloud/api/v1/scim/Groups

  5. Retrieve the value of the HTTP response header named x-csrf-token.

    You must include x-csrf-token with every HTTP request that you make to the API.

Results

At this point, you can make POST, PUT, and DELETE requests to a browser-based domain, so long as you continue to include the Authorization, x-csrf-token, and x-sap-sac-custom-auth HTTP headers, and the access token’s validity period has not been reached.