Post

Replies

Boosts

Views

Activity

JWT for App Store Server API requests
Hello, I'm trying to generate a JWT in C# for calling this endpoint -> https://developer.apple.com/documentation/appstoreserverapi/look_up_order_id I have followed the instructions in the documentation, but I'm always getting "Unauthenticated" as a response. The private key used is of type "In-App Purchase" as the documentation says. Here you have a response with a Request ID: Unauthenticated Request ID: YGV3ELXFCFHA5IPRZEW76S66NQ.0.0 This is the code used to generate the JWT: public string CreateNewApiToken() { const string audience = "appstoreconnect-v1"; var kid = "***"; var privateKey = "***"; var bundleId = "***"; var issuerId = "***"; var now = DateTime.UtcNow; using var ecdsa = ECDsa.Create(); ecdsa?.ImportPkcs8PrivateKey(Convert.FromBase64String(privateKey), out _); var signingCredentials = new SigningCredentials(new ECDsaSecurityKey(ecdsa), SecurityAlgorithms.EcdsaSha256); signingCredentials.Key.KeyId = kid; var payload = new JObject { { "iss", issuerId }, { "iat", now.ToUnixTime() }, { "exp", now.AddMinutes(30).ToUnixTime() }, { "aud", audience }, { "bid", bundleId} }; var handler = new JsonWebTokenHandler(); var token = handler.CreateToken(payload.ToJson(), signingCredentials); return token; } Thanks in advance.
2
0
804
Sep ’23