Skip to content

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

Merged
XAMPPRocky merged 1 commit into
XAMPPRocky:mainfrom
kyle-leonhard:reuse-client-with-access-token
Jan 13, 2025
Merged

Enable client reuse when authenticating with app user access tokens#740
XAMPPRocky merged 1 commit into
XAMPPRocky:mainfrom
kyle-leonhard:reuse-client-with-access-token

Conversation

@kyle-leonhard

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

@XAMPPRocky

Copy link
Copy Markdown
Owner

Thank you for your PR!

@XAMPPRocky XAMPPRocky merged commit 4106251 into XAMPPRocky:main Jan 13, 2025
@github-actions github-actions Bot mentioned this pull request Jan 13, 2025
kyle-leonhard added a commit to kosolabs/koso that referenced this pull request Feb 26, 2025
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