I want to login auth0 using Usename/Password for getting AccessToken.

{
  "error": "server_error",
  "error_description": "Authorization server not configured with default connection."
}

Solution: https://stackoverflow.com/questions/69419470/auth0-error-authorization-server-not-configured-with-default-connection

Methods

1. Make sample user

  • Navigate to your dashboard - manage.auth0.com/dashboard
  • On the left menu, click on User Management -> Users
  • Click on + Create User

username: e2e-test@example.com
password: PassW0rd

2. Get AccessToken (Failed)

$ curl 'https://<tenant name>.auth0.com/oauth/token' --data-raw 'client_id=<clientId of application>&username=e2e-test@example.com&password=PassW0rd&grant_type=password&scope=openid+name+email+nickname&connection=Username-Password-Authentication' | jq
{
  "error": "unauthorized_client",
  "error_description": "Grant type 'password' not allowed for the client.",
  "error_uri": "https://auth0.com/docs/clients/client-grant-types"
}

3. Add Grant

Open https://auth0.com/docs/api/management/v2/clients/patch-clients-by-id . Set Authorized Token. Update Grant Type path: body

{
  "grant_types": [
		"password",
		"http://auth0.com/oauth/grant-type/password-realm"
	]
}

url: https://<tenant name>.auth0.com/api/v2

A Curl command with the above parameters would look like this.

curl -L -X PATCH 'https://<tenant name>.auth0.com/api/v2/clients/<clientId of application>' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer 🔒' \
-d '{"grant_types":["password","http://auth0.com/oauth/grant-type/password-realm"]}'

Ref: https://community.auth0.com/t/error-grant-type-password-not-allowed-for-the-client-for-resource-owner-password-flow/6951/2

4. Get AccessToken (Failed)

ReTry, but

$ curl 'https://<tenant name>.auth0.com/oauth/token' --data-raw 'client_id=<clientId of application>&username=e2e-test@example.com&password=PassW0rd&grant_type=password&scope=openid+name+email+nickname&connection=Username-Password-Authentication' | jq
{
  "error": "server_error",
  "error_description": "Authorization server not configured with default connection."
}

5. Set Default Directory

  • Navigate to your dashboard - manage.auth0.com/dashboard
  • On the left menu, click on Setting
  • Scroll down to “API Authorization Settings”
  • Enter Username-Password-Authentication in the “Default Directory” input
  • Hit save - It typically takes about 30secs for changes to take effect

Ref: https://stackoverflow.com/questions/69419470/auth0-error-authorization-server-not-configured-with-default-connection

6. Test

$ curl --request GET \
  --url https://<tenant name>.auth0.com/userinfo \
  --header 'content-type: application/json' \
  --header 'Authorization: Bearer <AccessToken>'
{
  "access_token": "🔒",
  "id_token": "🔒",
  "scope": "openid email",
  "expires_in": 86400,
  "token_type": "Bearer"
}

7. Next

Write Go Test Code Note

References

Ref: https://community.auth0.com/t/get-user-token-by-email-and-password-from-the-api/77391
Ref: https://community.auth0.com/t/is-there-an-easy-way-to-get-a-user-access-token-for-testing/73170