-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat: add support for visitor api key #363
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple suggestions but overall looks good
Only other comment is that the posit-sdk-py side of this is on hold until I can chat with Kelly about the naming convention she prefers us to use: Visitor vs Viewer across the sdks, docs, and connect server. So maybe this PR needs to be held up until then as well? |
@mconflitti-pbc Sounds good, I'll hold off on merging till I hear from you about that. Thanks for moving that convo forward while I'm on jury duty! |
Intent
Add the ability to create a Connect client using content visitor-scoped authentication.
Fixes #362
Approach
Added a token argument to the
connect()
function. When passed a token and running on Connect, performs an OAuth credential exchange request to get a visitor API key and returns a client using that API key instead. When an argument is provided totoken
but code is not running on Connect, prints a message and returns a client using the provided API key.I considered a few tradeoffs:
NULL
value. This implementation breaks with the convention —token
argument has no default value, and I usemissing()
to tell if it has been provided.NULL
, so sticking to convention means that we can't tell the difference between the cases where a user just wants to use the API key, or is using thetoken
arg but running the content locally.token
is provided correctly, using the API key locally but using the token on Connect.NULL
arg convention because this allows us to log a console message when the content is running locally and we see that they provided a NULL arg totoken
and are using the API key.token
argument actually comes before the pre-existingprefix
argument. This is fine, I think: theprefix
argument would be used when users want to set the env var value of bothserver
andapi_key
, the first two arguments, so it should basically never be called with them — which means it would always be called by name and not positionally, and is fine to move. Thetoken
argument makes more sense to be up front with those two, although it's unlikely to ever be called positionally, because I doubt you'd ever call it and also pass in aserver
URL.connect()
function, rather than the Connect object'sConnect$new()
initialization function. This… just made more sense to me. This is logic that wraps the direct initialization of the object.connect()
, when you use a token on Connect, the app logs will contain the lineDefining Connect with the server: {server}
twice. This is because that line is logged fromConnect$new()
. I guess we could move that log line out of that function, but that didn't seem like a huge priority. And technically, both clients are defined, because the first one is used to make the OAuth request.token_fallback_api_key
which is kinda verbose — I wanted to clarify that it wasn't, like, just a fallback API key that's used if the regularapi_key
is not present.Manual Verification
You can test this with the following Shiny app:
To publish this to Connect with the dev version of
connectapi
:app.R
.renv::init()
,renv::install("posit-dev/connectapi@toph/viewer-api-key")
, andrenv::snapshot()
.Checklist
NEWS.md
(referencing the connected issue if necessary)?devtools::document()
?