Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@atheriel
Copy link
Collaborator

This commit adds support for another major Azure authentication approach: the OAuth authorization code flow, as used by the Azure CLI.

This is a good choice for authentiation during development on desktop, and Microsoft recommends it for Azure OpenAI because it doesn't require storing sensitive long-lived secrets like API keys.

All of this is pretty stock httr2 OAuth stuff, despite the fact that Entra ID has its own... idiosyncrasies. I also went out of the way to add a really specific error message for what I believe to be a common source of problems: misconfiguration of Azure's RBAC. It looks as follows:

Error in `req_perform_connection()` at elmer/R/httr2.R:36:3:
! HTTP 401 Unauthorized.
• PermissionDenied: Principal does not have access to API/Operation.
ℹ Your user or service principal likely needs one of the following
  roles: Cognitive Services OpenAI User, Cognitive Services OpenAI
  Contributor, or Cognitive Services Contributor.

I haven't added any unit tests (I don't know how to do so for this kind of interactive OAuth flow), but at least the help documentation has been updated.

roles: {.emph Cognitive Services OpenAI User},
{.emph Cognitive Services OpenAI Contributor}, or
{.emph Cognitive Services Contributor}.",
keep_whitespace = FALSE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need that? I think it will get re-wrapped anyway?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my testing it doesn't get re-wrapped without this 😭.

This commit adds support for another major Azure authentication
approach: the OAuth authorization code flow, as used by the Azure CLI.

This is a good choice for authentiation during development on desktop,
and Microsoft recommends it for Azure OpenAI because it doesn't require
storing sensitive long-lived secrets like API keys.

All of this is pretty stock httr2 OAuth stuff, despite the fact that
Entra ID has its own... idiosyncrasies. I also went out of the way to
add a really specific error message for what I believe to be a common
source of problems: misconfiguration of Azure's RBAC. It looks as
follows:

    Error in `req_perform_connection()` at elmer/R/httr2.R:36:3:
    ! HTTP 401 Unauthorized.
    • PermissionDenied: Principal does not have access to API/Operation.
    ℹ Your user or service principal likely needs one of the following
      roles: Cognitive Services OpenAI User, Cognitive Services OpenAI
      Contributor, or Cognitive Services Contributor.

I haven't added any unit tests (I don't know how to do so for this kind
of interactive OAuth flow), but at least the help documentation has been
updated.

Signed-off-by: Aaron Jacobs <[email protected]>
@atheriel
Copy link
Collaborator Author

Got a real Entra ID RBAC setup working with this today, so I consider it good to go.

@hadley
Copy link
Member

hadley commented Jan 27, 2025

Feel free to merge once the CI checks pass.

@atheriel atheriel merged commit ebcd711 into main Jan 27, 2025
11 checks passed
@atheriel atheriel deleted the azure-cli-auth branch January 27, 2025 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants