OAuth – Register your Application within DRIVR

Creating an ApplicationConsumer allows you to register your application in DRIVR in order to authenticate users against our APIs and manage OAuth flows using the DomainAuthenticationMethods from the previous guide. Additionally, you can control how your app interacts with DRIVR's APIs and manage different OAuth grantTypes.

The DRIVR Login UI simplifies the process by handling user authorization dialogs and token requests. To enable this, your app must be linked to an OAuth consumer/client, which is represented by an ApplicationConsumer. The identifier serves as the client_id in authentication requests.

A grantType defines how your application interacts with DRIVR's authentication system. Here are the available grant types:

  1. Authorization Code (AUTHORIZATION_CODE):

    • Used for server-based flows where an authorization code is exchanged for an access token.
    • Requires at least one redirectUri to securely handle sensitive information.
    • Ensures that users are not redirected to unauthorized locations.
  2. Password (PASSWORD):

    • Allows exchanging a username and password for an access token.
    • Suitable for trusted applications where user credentials are directly handled.
  3. Refresh Token (REFRESH_TOKEN):

    • Enables the issuance of long-lasting refresh tokens to request new access tokens.
    • Refresh tokens are tied to the client they were issued for and can be combined with other grant types.

The following example demonstrates how to create a new ApplicationConsumer for local development. This setup allows your app to authenticate against the DRIVR API.

Option 1: Navigate to the DRIVR UI:

  1. Navigate to the DRIVR UI and go to Settings -> Application Consumers.
  2. Click on Add Application Consumer to create a new consumer.
  3. Provide the name and a unique slug for the application within the Domain.
  4. Select the required Grant Types from AUTHORIZATION_CODE, PASSWORD, and REFRESH_TOKEN. Specify Scopes such as profile, email, etc.
  5. Add Redirect URIs. (Note: At least one redirectUri is mandatory if the grant type is AUTHORIZATION_CODE; otherwise, it is optional.)
  6. Click Create to save the new Application Consumer.

Option 2. Use the GraphQL API:
Alternatively, you can use the following GraphQL mutation to create an ApplicationConsumer:

mutation createApplicationConsumer {
  createApplicationConsumer(
    name: "my-new-app",
    slug: "my-app",
    defaultRedirectUri: "http://localhost:8080/auth/callback",
    redirectUris: [
        "http://localhost:8080/auth/callback",
        "http://localhost:8080/auth/another-callback"
    ],
    secret: "nuq1u6k4nWSNgrPEDbHXTqWN4APERZ8X1LPcY9Hov7gHnPcfD1hcNhmMOzoYkAVs",
    grantTypes: [
        REFRESH_TOKEN,
        AUTHORIZATION_CODE
    ],
    scopes: [
        "profile",
        "email"
    ]
  ) {
    uuid
    identifier
    defaultRedirectUri
    redirectUris
    status
    grantTypes
    name
    slug
    scopes
  }
}
Response
{
  "data": {
    "createApplicationConsumer": {
        "uuid": "3bd72e78-1f23-2781-8b65-b84e4a2a4765",
        "identifier": "my-app.localhost",
        "defaultRedirectUri": "http://localhost:8080/auth/callback",
        "redirectUris": [
            "http://localhost:8080/auth/callback",
            "http://localhost:8080/auth/another-callback"
        ],
        "status": "ACTIVATED",
        "grantTypes": [
            "AUTHORIZATION_CODE",
            "REFRESH_TOKEN"
        ],
        "name": "my-new-app",
        "slug": "my-app",
        "scopes": [
            "profile",
            "email"
        ]
    }
  }
}

  1. name: The name of your application (e.g., "my-new-app").
  2. slug: A unique identifier for your application (e.g., "my-app").
  3. defaultRedirectUri: The primary redirect URI for your app (e.g., "http://localhost:8080/auth/callback").
  4. redirectUris: A list of allowed redirect URIs for your app.
  5. secret: The client secret used for secure communication.
  6. grantTypes: The grant types your app supports (Options: AUTHORIZATION_CODE, REFRESH_TOKEN, PASSWORD).
  7. scopes: The permissions your app requests (e.g., "profile", "email").

Setting up an Application Consumer is a crucial step in enabling your app to interact with DRIVR's APIs securely.

By configuring the appropriate grant types and redirect URIs, you can ensure a seamless authentication experience for your users. Use the DRIVR UI or the provided GraphQL mutation to create and manage Application Consumers for your domain.