Share via

Authenticating with Postgres Flex Server using Active Directory as a Service Principal throws error

awf09j 40 Reputation points
2023-08-02T18:21:45.76+00:00

I'm trying to authenticate as a Service Principal using the @azure/identity npm library.

The AAD hierarchy:

-- pg-contributors (group) contains:
---- app-devs (group)
-------- me (user)
---- web-app (service principal)

My code:

const scope = 'https://ossrdbms-aad.database.windows.net';
const credential = new ClientSecretCredential(tenantId, clientId, clientId);
const testToken = await credential.getToken(scope); // this throws

The error:

AuthenticationRequiredError: invalid_scope: 70011 - [2023-08-02 18:09:30Z]: AADSTS70011: The provided request must include a 'scope' input parameter. The provided value for the input parameter 'scope' is not valid. The scope https://ossrdbms-aad.database.windows.net is not valid.

The exact same scope and call works as myself using the AzureCLI credential. Now I'm trying to authenticate with the service principal creds and am getting an error. Anyone know how to fix?

Azure App Service
Azure App Service

Azure App Service is a service used to create and deploy scalable, mission-critical web apps.

Microsoft Security | Microsoft Entra | Microsoft Entra ID

1 answer

Sort by: Most helpful
  1. Marilee Turscak-MSFT 37,396 Reputation points Microsoft Employee Moderator
    2023-08-09T18:27:33.54+00:00

    Hi @awf09j ,

    I spoke with the PG and took a look at the documentation on this here: Connect with Managed Identity - Azure Database for PostgreSQL - Single Server | Microsoft Learn

    We managed to test using Postman. Passing this scope<https://ossrdbms-aad.database.windows.net/> returns the same error as what you are getting (AuthenticationRequiredError: invalid_scope). For the managed Identity, you need to add the /.default scope as shown in the example. Tested on postman and we were able to get an access token. 

    Let me know if this helps and if you have further questions.

    If the information helped you, please Accept the answer. This will help us as well as others in the community who may be researching similar information.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.