Skip to content
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

get_current_user #54

Open
edavidaja opened this issue Feb 27, 2024 · 8 comments
Open

get_current_user #54

edavidaja opened this issue Feb 27, 2024 · 8 comments
Labels
enhancement New feature or request sdk

Comments

@edavidaja
Copy link

Shiny supports this via session.user, for other frameworks we should support this via SDK:

@nealrichardson
Copy link
Collaborator

We just added #51. So should we plan to update those guides to use the SDK to get the user? Or something else?

@mmarchetti
Copy link

mmarchetti commented Feb 28, 2024

The API call in #51 will return the user who owns the API key the client is configured to use. The scenario here is a deployed app that wants to know the identity of visiting users who are identified to Connect (but not the app) via a session cookie. Connect embeds their information in an HTTP header that the app receives. Code to extract HTTP headers from the inbound request is framework-specific.

@tdstein
Copy link
Collaborator

tdstein commented Feb 28, 2024

Is visitor the appropriate name for this entity? While user for "me".

e.g.,

client.visitor

@nealrichardson
Copy link
Collaborator

I'm not sure it comes from client. From the looks of those examples, it's a utility that parses a response header or something, which seems to vary across applications as to how it's exposed. So the SDK would be providing a helper function to encapsulate that?

@edavidaja
Copy link
Author

So the SDK would be providing a helper function to encapsulate that?

That was what I had in mind.

@tdstein
Copy link
Collaborator

tdstein commented Feb 29, 2024

Got it. Is visitor still appropriate for a logical name?

I'm thinking the following where get_visitor is the tbd helper method

import json

from posit.connect import Client

def get_visitor() -> dict:
    return {'username': 'taylor_steinberg', 'groups': ['rsc_team']}

with Client() as client:
    visitor = get_visitor()
    user = client.users.find_one(lambda user: user["username"] == visitor["username"])
    print(json.dumps(user))

@edavidaja
Copy link
Author

I think "visitor" is fine and it's a word we use in other places in the documentation. A good alternative is "viewer"--it overlaps with the Connect role, which I think is fine in this case.

@mmarchetti
Copy link

visitor = get_visitor()

Looking at our example code for Flask, FastAPI and Streamlit, it will be difficult for the API to have that shape since we don't know which framework is in use. We might need a separate helper function per framework.

@tdstein tdstein added the enhancement New feature or request label Apr 18, 2024
@tdstein tdstein added this to the 0.3.0 milestone Apr 26, 2024
@tdstein tdstein removed this from the 0.3.0 milestone Sep 4, 2024
@tdstein tdstein added the sdk label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sdk
Projects
None yet
Development

No branches or pull requests

4 participants