# Connecting to non-default Database in a password grant flow

**URL:** <https://community.auth0.com/t/connecting-to-non-default-database-in-a-password-grant-flow/86960>\
**Category:** Get Help\
**Tags:** password, database-connections, oauth2\
**Created:** [July 14, 2022, 9:16am UTC](https://community.auth0.com/t/connecting-to-non-default-database-in-a-password-grant-flow/86960 "2022-07-14T09:16:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![guybrush](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/guybrush/32/33545_2.png) [@guybrush](https://community.auth0.com/u/guybrush)\
**Post date:** [July 14, 2022, 9:16am UTC](https://community.auth0.com/t/connecting-to-non-default-database-in-a-password-grant-flow/86960/1 "2022-07-14T09:16:24Z")

</div>

I’m using a password grant OAuth flow, but can’t connect to a non-default Database/Connection.

- I’ve got two applications configured on a tenant, each with their own database.

- Both are using a password grant flow.

- I’m testing both applications on the command line with curl, using sample code from the docs, so am confident it’s not code related:

```shell
export TENANT=foo;
export CLIENT_ID=bar;
export CLIENT_SECRET=baz;
export AUDIENCE=qux;
export USERNAME=quux;
export PASSWORD=corge;

curl --request POST \
  --url https://$TENANT/oauth/token \
  --header 'content-type: application/json' \
  --data '{"client_id":"$CLIENT_ID", "client_secret":"$CLIENT_SECRET", "audience":"$AUDIENCE", "grant_type":"password", "username": "$USERNAME", "password": "$PASSWORD"}'

```

1. The application that uses the default database on the tenant works fine and can successfully receive a token
2. but the application that uses the non-default DB returns an error:

```json
{
  "error": "invalid_request",
  "error_description": "connection is disabled (client_id: $SECOND_CLIENT_ID - connection: $DEFAULT_DATABASE_NAME)"
}

```

- Application #2 is configured with Database #2 enabled and Database #1 disabled.
- Both applications are configured with password grant type enabled and can’t see any difference in their configuration
- I switched Application #2 to talk to Database #1 and it works OK, so seems like it is specifically related to the connection

The issue I’m facing seems to be the same as [this previous post](https://community.auth0.com/t/connection-is-disabled-why-is-auth0-not-trying-the-enabled-connection/21372/3), but that user wanted to switch DBs so could resolve their issue by changing their default connection, whereas I need to keep both active.

I’ve tried passing `connection` as parameter in my request body (similar to when making a create user request), and have also tried a `realm ` param (both with the connection name or its ID), but neither have worked.

Any ideas on what I’m missing? Please let me know if you need more details

* * *

**Edit to add:**

Checking the monitoring in the Console, it gives:

### Summary

- **Occurred:** a few seconds ago at 2022-07-14 09:18:39.192 UTC
- **Type:** Failed Exchange
- **Description:** connection is disabled (client\_id: `$CLIENT_ID_2` - connection: `$DEFAULT_DATABASE_NAME`)
- **Connection:** `$DEFAULT_DATABASE_NAME`
- **Application:** `$APPLICATION_NAME_2` (`$CLIENT_ID_2`)
- **User:** `$USERNAME`

---

<div class="post-metadata">

**Author:** ![guybrush](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/guybrush/32/33545_2.png) [@guybrush](https://community.auth0.com/u/guybrush)\
**Post date:** [July 14, 2022, 9:33am UTC](https://community.auth0.com/t/connecting-to-non-default-database-in-a-password-grant-flow/86960/2 "2022-07-14T09:33:34Z")

</div>

Typically just after posting [I found this page](https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-resource-owner-password-flow#configure-realm-support) in the docs that mention you need to change `grant_type` in order to use the realm parameter.

At first (on speed reading) I tried tho use `"grant_type": "password-realm"` but received an error:

```json
{
  "error": "unauthorized_client",
  "error_description": "Grant type 'password-realm' not allowed for the client.",
  "error_uri": "https://auth0.com/docs/clients/client-grant-types"
}

```

Checking the error URI and back to the original page, I realised that grant\_type should be the fully qualified URI:

```bash
http://auth0.com/oauth/grant-type/password-realm

```

And now this is working successfully.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [November 4, 2022, 2:46pm UTC](https://community.auth0.com/t/connecting-to-non-default-database-in-a-password-grant-flow/86960/3 "2022-11-04T14:46:28Z")

</div>


