-
Notifications
You must be signed in to change notification settings - Fork 10
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
[DOCS]: Example on how to create a GitHubClient
with different authentication providers
#122
Comments
👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with |
Hmm...I'm not sure I understand what you're after, sorry! Do you mind providing a little more detail, and/or maybe an imaginative code snippet that would reflect what you're looking for? |
Hi @kfcampbell! Here are some details. I have a Multi-user system, users provide their own GH PAT. I couldn't figure out how to modify the token directly for each request as the client disallows that. So I cheated: public class AsyncLocalTokenProvider : IAccessTokenProvider
{
public static readonly AsyncLocal<string> Token = new(s => _ = s.CurrentValue);
AllowedHostsValidator IAccessTokenProvider.AllowedHostsValidator => new();
public Task<string> GetAuthorizationTokenAsync(Uri requestUri, Dictionary<string, object>? additionalAuthenticationContext = null, CancellationToken cancellationToken = default) => Task.FromResult(Token.Value ?? string.Empty);
} Usage private static readonly HttpClientRequestAdapter Factory = new ClientFactory()
.WithUserAgent($"InfinityFlow-{nameof(GitHubV1)}", System.Reflection.Assembly.GetAssembly(typeof(GitHubV1))?.GetName()?.Version?.ToString()
?? "0.0.0")
.WithRequestTimeout(TimeSpan.FromSeconds(100))
.WithAuthenticationProvider(new TokenAuthProvider(new GitHubAsyncLocalTokenProvider()))
.WithBaseUrl("https://api.github.com")
.Build();
private static readonly GitHubClient GitHubClient = new(Factory);
var credential = await Credential.Get();
AsyncLocalTokenProvider.Token.Value = credential.Password; There has to be a better way to do this with Kiota :D |
Describe the need
I have a system where users can provide PATs to use the GH API via our system.
We would like to be able to create a new authentication provider each time, however since the the client factory is immutable it doesn't seem to be possible.
I'm probably missing something, any guidance is welcome!
SDK Version
No response
API Version
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: