JDBC Driver for Azure Cosmos DB

Build 23.0.8839

Creating a Custom OAuth Application

Creating a Custom OAuth Application

Azure Cosmos DB supports authentication using Azure AD and Azure Service Principal, both of which are OAuth-based.

This topic describes how to:

  • create and register custom OAuth application for Azure AD or Azure Service Principal
  • create a custom OAuth application for use with client credentials

Azure AD

In portal.azure.com:
  1. Log in to https://portal.azure.com.
  2. In the left-hand navigation pane, select Azure Active Directory, then applicationRegistrations.
  3. Click New registration.
  4. Enter a name for the application.
  5. Select the desired tenant setup: single- or multi-tenant, and public or private use.

    • If you select the default option, "Accounts in this organizational directory only", you must set the AzureTenant connection property to the Id of the Azure AD Tenant when establishing a connection with the CData JDBC Driver for Azure Cosmos DB. Otherwise, the authentication attempt fails with an error.
    • If your application is for private use only, specify Accounts in this organization directory only.
    • If you want to distribute your application, choose one of the multi-tenant options.

  6. Set the redirect url to http://localhost:33333 (the driver's default) OR specify a different port and set CallbackURL to the exact reply URL you defined.
  7. Click Register to register the new application. An application management screen displays.
    Note the value in Application (client) ID as the OAuthClientId and the Directory (tenant) ID as the AzureTenant.
  8. Navigate to Certificates & Secrets and define the application authentication type. There are two types of authentication available: certificate (recommended) or client secret.

    • For certificate authentication: In Certificates & Secrets, select Upload certificate, then upload the certificate from your local machine.
    • For creating a new client secret: In Certificates & Secrets, select New Client Secret for the application and specify its duration. After the client secret is saved, Azure Cosmos DB displays the key value. Copy this value, as it is displayed only once. This value becomes the OAuthClientSecret.

  9. Select API Permissions > Add > Delegated permissions.
  10. Save your changes.
  11. If you have specified the use of permissions that require admin consent (such as the Application Permissions), you can grant them from the current tenant on the API Permissions page.

Azure Service Principal

To use Azure Service Principal authentication, you must set up the ability to assign a role to the authentication application, then register an application with the Azure AD tenant to create a new Service Principal. That new Service Principal can then leverage the assigned role-based access control to access resources in your subscription.

In portal.azure.com:

  1. Create a custom OAuth AD application, as described above.
  2. Use the search bar to search for the Subscriptions service.
  3. Open the Subscriptions page.
  4. Select the subscription to which to assign the application.
  5. Open the Access control (IAM).
  6. Select Add > Add role assignment. Azure Cosmos DB opens the Add role assignment page.
  7. Assign your custom Azure AD application the role of Owner.

Consent for Client Credentials

OAuth supports the use of client credentials to authenticate. In a client credentials OAuth flow, credentials are created for the authenticating application itself. The auth flow acts just like the usual auth flow except that there is no prompt for an associated user to provide credentials. All tasks accepted by the application are executed outside of the context of a default user.

Note: Since the embedded OAuth credentials authenticate on a per-user basis, you cannot use them in a client OAuth flow. You must always create a custom OAuth application to use client credentials.

In portal.azure.com:

  1. Create a custom OAuth application, as described above.
  2. Navigate to App Registrations.
  3. Find the application you just created, and open API Permissions.
  4. Select the Microsoft Graph permissions. There are two distinct sets of permissions: Delegated and Application.
  5. Under Application Permissions, select the permissions you require for your integration.

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 23.0.8839