Skip to content

Azure OpenAI OAuth - R Shiny chat app #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

joshyam-k
Copy link

work to fulfill: https://github.com/posit-dev/connect/issues/31840

Very open to feedback on how best to market/present this gallery app since it's so reliant on specific users being given the correct data action roles to access an Azure OpenAI model deployment. I tried my best to document this in the "Usage" section of the README.md.

This app has been deployed as an example here, but only members of the "Connect" user group will be able to properly interact with it.

azure_chat <- ellmer::chat_azure_openai(
deployment_id = "gpt-4o-mini",
api_version = "2024-12-01-preview",
endpoint = "https://8ul4l3wq0g.openai.azure.com",

Choose a reason for hiding this comment

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

is this a generic api endpoint or something tied to a specific integration?

Copy link
Author

Choose a reason for hiding this comment

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

it's a specific Azure OpenAI resource endpoint within the posit org

Choose a reason for hiding this comment

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

Gotcha okay. So sort of separate from the oauth integration itself but also tied to it in a way. Name-wise, it would seem that this would be information that would be bundled with the integration itself versus needing to know the endpoint as a separate piece of information. For AWS bedrock, you just specify the model and and the creds tell AWS what you have access to. Shame Azure doesnt do the same thing :)

Was that detail discussed at all when building the integration? It sort of continues moving the feature from "OAuth integrations" to just "integrations" which I like since some services we want to use require more metadata to be managed by admins like this endpoint.

I don't feel super strongly about this, but does raise a question in my mind. cc @zackverham @nihara-thomas

Comment on lines 31 to 37
if (Sys.getenv("POSIT_PRODUCT") == "CONNECT") {

client <- connectapi::connect()

user_session_token <- session$request$HTTP_POSIT_CONNECT_USER_SESSION_TOKEN
oauth_response <- connectapi::get_oauth_credentials(client, user_session_token)
credentials <- list(Authorization = paste("Bearer", oauth_response$access_token))

Choose a reason for hiding this comment

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

could be worth taking a look at what I am doing here to surface a setup screen if it is determined that no integration is added to the gallery app. #179 -> line

Copy link
Author

@joshyam-k joshyam-k Jun 25, 2025

Choose a reason for hiding this comment

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

just added this in 271f481!

It's a messier implementation than the example you linked, but that's mainly because connectapi::connect surfaces the 212 error code as a message instead of explicitly throwing the error. It seems like "grep"-ing the captured message output consistently captures the error code we're looking for, but maybe there's a much easier way to do this that I'm not yet aware of.

This approach is also limited in that it's checking for any enabled oauth integration, not specifically the azure openai one, but my guess is that it's okay for this application.

"tags": ["r", "shiny"],
"minimumConnectVersion": "2025.06.0",
"requiredFeatures": ["OAuth Integrations"],
"version": "0.0.0"

Choose a reason for hiding this comment

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

you can bump this to 0.0.1 to release it

@@ -0,0 +1,19 @@
# R Shiny Chat App

Choose a reason for hiding this comment

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

I am wondering if this should be named something more specific than this since the goal is to showcase the Azure OpenAI integration. Building something more generic other than this example could then not be tied to this newer Connect version.

Copy link
Author

Choose a reason for hiding this comment

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

ah, good point. I'll go ahead and change the name of the directory as well as all other instances of the name.

@mconflitti-pbc
Copy link

Overall, great work! Some comments of things that may need some clarification or tweaking.

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.

2 participants