'Creating apple JWT token

Im trying to the Apple App Store Connect API from a .core application.

I currently have

var key = <contents of p8 file>;

var credentials = new SigningCredentials(
    new SymmetricSecurityKey(Encoding.ASCII.GetBytes(key)),
    SecurityAlgorithms.EcdsaSha256
);

var header = new JwtHeader(credentials);
header.Add("kid", KeyID);   

var payload = new JwtPayload
{
    { "aud ", "appstoreconnect-v1"},
    { "exp", exp},
    {"iss", issuerID }
};

var secToken = new JwtSecurityToken(header, payload); 
var handler = new JwtSecurityTokenHandler();
var tokenString = handler.WriteToken(secToken);

The problem im having is

Unable to create the SignatureProvider.\nAlgorithm: 'System.String', SecurityKey: 'Microsoft.IdentityModel.Tokens.SymmetricSecurityKey'\n is not supported. The list of supported algorithms is available here: https://aka.ms/IdentityModel/supported-algorithms"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source