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

Enable client reuse when authenticating with app user access tokens #740

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kyle-leonhard
Copy link
Contributor

@kyle-leonhard kyle-leonhard commented Dec 5, 2024

This PR allows octocrab instances to be reused with different Github app user access tokens, similar the installation function enabling an instance to be reused with different installations of an app.

The motivation is to avoid creating a new connection every time a request needs made for a different user, user access token. I didn't see any good way to reuse or provide the connection created in build (code)

Here's how it looks:

let octocrab = OctocrabBuilder::new().build()?;

// Later, use the client with many, varying access tokens.
let octocrab = octocrab.user_access_token(token)?

An alternative is to expose an Octocrab::toBuilder method to effectively clone the existing client with varying configuration. This looks hard given how configuration ends up embedded in service layers.

User access token documentation: https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-user-access-token-for-a-github-app

@kyle-leonhard
Copy link
Contributor Author

Immediately after posting this PR I found:

.with_service(client)
.

I think that'd solve my issue. Though there is still value in enabling reuse in the manner of this PR. I'm hoping maintainers will have an opinion

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.

1 participant