Closed github-apptesting closed 3 years ago
This is how my code looks like -
StringPrivateKeySource privateKeySource = new StringPrivateKeySource(
--key initialization code--);
GitHubJwtFactoryOptions options = new GitHubJwtFactoryOptions
{
AppIntegrationId = --Id initialization code--),
ExpirationSeconds = MaxTokenExpirationSeconds
};
GitHubJwtFactory factory = new GitHubJwtFactory(privateKeySource, options);
string token = factory.CreateEncodedJwtToken();
m_gitHttpClient = new GitHubClient(
new ProductHeaderValue(
--header initialization code--));
This is the exception -
INNER EXCEPTION, System.AggregateException: One or more errors occurred. ---> Octokit.AuthorizationException: Bad credentials at Octokit.Connection.HandleErrors(IResponse response) at Octokit.Connection.1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Octokit.ApiConnection.<GetPage>d__41
1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Octokit.ApiConnection.<>c__DisplayClass17_0`1.<
I guess the problem ist that you are trying to access a non-top-level API. For these, you need an installation token. So after getting a GitHub client, you need to get another token for your installation similar to this:
var app = await m_gitHttpClient.GitHubApps.GetCurrent();
var installation = await m_gitHttpClient.GitHubApps.GetInstallationForCurrent(installationId);
var installationToken = await m_gitHttpClient.GitHubApps.CreateInstallationToken(installationId);
m_gitHttpClient = new GitHubClient(new ProductHeaderValue($"myApp-{installationId}"))
{
Credentials = new Credentials(installationToken.Token)
};
Hi, I used the DLLs as per documentation but I was consistently getting error saying bad credentials. Thanks