0

I'm attempting authentication between services via Google's Cloud Endpoints by following this article: https://cloud.google.com/endpoints/docs/openapi/service-account-authentication#java

Been struggling to get the JWT token generation to work in C#. Here's the code I got so far:

var creds = await GoogleCredential.GetApplicationDefaultAsync();
var privateKey = ((ServiceAccountCredential)creds.UnderlyingCredential).Key;

var claims = new List<Claim>();
claims.Add(new Claim("iat", "some time"));
claims.Add(new Claim("exp", "some time"));
claims.Add(new Claim("iss", "some issuer"));
claims.Add(new Claim("aud", "some audience"));
claims.Add(new Claim("sub", "some subject"));
claims.Add(new Claim("email", "some email"));

Dictionary<string, object> payload = claims.ToDictionary(k => k.Type, v => (object)v.Value);

var token = Jose.JWT.Encode(payload, privateKey, Jose.JwsAlgorithm.RS256);

the token gets generated and I do see the claims in JWT.io but it keeps saying that the signature is invalid. What am I doing wrong? I am using Jose-Jwt package.

Newbie
  • 157
  • 4
  • 15

0 Answers0