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

[BUG]: A JSON web token could not be decoded #2833

Open
1 task done
greggjensencart opened this issue Dec 15, 2023 · 1 comment
Open
1 task done

[BUG]: A JSON web token could not be decoded #2833

greggjensencart opened this issue Dec 15, 2023 · 1 comment
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented Type: Support Any questions, information, or general needs around the SDK or GitHub APIs

Comments

@greggjensencart
Copy link

What happened?

Any chance you have an example of generating the GitHub App JWT? I keep running into the following error:

Octokit.AuthorizationException: A JSON web token could not be decoded
   at Octokit.Connection.HandleErrors(IResponse response) in /_/Octokit/Http/Connection.cs:line 766
   at Octokit.Connection.RunRequest(IRequest request, CancellationToken cancellationToken, Func`2 preprocessResponseBody) in /_/Octokit/Http/Connection.cs:line 747
   at Octokit.Connection.Run[T](IRequest request, CancellationToken cancellationToken, Func`2 preprocessResponseBody) in /_/Octokit/Http/Connection.cs:line 732
   at Octokit.ApiConnection.Get[T](Uri uri, IDictionary`2 parameters)

Here is the code I am using. I have tried 10 variations and libraries.

	var pem = @"
-----BEGIN RSA PRIVATE KEY-----
PRIVATE KEY
-----END RSA PRIVATE KEY-----
";
	using var rsa = RSA.Create();
	rsa.ImportFromPem(pem);

	var signingCredentials = new SigningCredentials(new RsaSecurityKey(rsa), SecurityAlgorithms.RsaSha256)
	{
		CryptoProviderFactory = new CryptoProviderFactory { CacheSignatureProviders = false }
	};

	var now = DateTimeOffset.Now;

	var jwt = new JwtSecurityToken(
		issuer: "111111",
		claims: new Claim[]{
			new ("iat",now.AddMinutes(-1).ToUnixTimeSeconds().ToString(), ClaimValueTypes.Integer)
		},
		expires: now.AddMinutes(10).Date,
		signingCredentials: signingCredentials
	);

	token = new JwtSecurityTokenHandler().WriteToken(jwt);

       _githubAppClient = new GitHubClient(new ProductHeaderValue("MyApp"), new InMemoryCredentialStore(credentials));
       var app = await _githubAppClient.GitHubApps.GetCurrent();

Versions

OctokIt 8.1.1

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@greggjensencart greggjensencart added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Dec 15, 2023
@nickfloyd nickfloyd added the Type: Support Any questions, information, or general needs around the SDK or GitHub APIs label Jan 4, 2024
@kfcampbell kfcampbell added Status: Up for grabs Issues that are ready to be worked on by anyone and removed Status: Triage This is being looked at and prioritized labels Jan 5, 2024
@shem8
Copy link

shem8 commented Feb 25, 2024

I have the same problem, it was because the new version of Node and starting using the new fetch api: https://github.com/nodejs/node/releases/tag/v18.0.0

What I'm doing right now is to add --no-experimental-fetch when running node, but this should be fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
Status: 🔥 Backlog
Development

No branches or pull requests

4 participants