I am trying to generate JWT token using below token and its generating as well but am get below error while making an actual google api call using the generated JWT.
Actual Code below :
{
string privateKeyPem = "testkeyfgdfa";
byte[] privateKeyRaw = Convert.FromBase64String(privateKeyPem);
// creating the RSA key
RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
provider.ImportPkcs8PrivateKey(new ReadOnlySpan<byte>(privateKeyRaw), out _);
RsaSecurityKey rsaSecurityKey = new RsaSecurityKey(provider);
// Generating the token
var now = DateTime.UtcNow;
var claims = new[] {
new Claim(JwtRegisteredClaimNames.Sub, "645564"),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
};
var handler = new JwtSecurityTokenHandler();
var token = new JwtSecurityToken
(
"645564",
"https://www.googleapis.com/oauth2/v4/token",
claims,
now.AddMilliseconds(-30),
now.AddMinutes(60),
new SigningCredentials(rsaSecurityKey, SecurityAlgorithms.RsaSha256)
);
// handler.WriteToken(token) returns the token.
Console.WriteLine( handler.WriteToken(token) );
}
Getting below error while making call to google API
{
"error": "invalid_scope",
"error_description": "Invalid OAuth scope or ID token audience provided."
}
My question is how to add scope ? cannot find a way to do this...
Appreciate your help and suggestions
------------------------------
V S
------------------------------