I am following this guide https://p.agnihotry.com/post/validating_sign_in_with_apple_authorization_code to be able to "server verify" an Apple AuthCode by sending a request to Apple.
These below are indications to generate client_secret:
Following are the steps to calculate the signature from the SHA-256:
- Generate r,s by signing using ecdsa.
- Append r and s, meaning join the r and s together.
- base64 url encode the appended result.
I am really struggling to find any examples on how to complete the first step. I previously generated a string that I assume I have to sign, and then somehow extract r and s. By "ecdsa signing" this string, I obtain a byte array, but cant really figure out how to solve the "Generate r,s by signing using ecdsa" piece, or how to basically obtain these "r,s".
Anybody that can shed any light, highly appreciated.
Current Sample code:
public static string GenerateAppleClientSecret(string data)
{
byte[] bytesData = Encoding.UTF8.GetBytes(data);
var ecDsa = ECDsaFromFile();
var signedData = ecDsa.SignData(bytesData, HashAlgorithmName.SHA256);
string r = "Where do I get r??";
string s = "Where do I get s??";
return Base64UrlEncoder.Encode(r + s);
}
public static ECDsa ECDsaFromFile()
{
var privateKey = LoadPrivateKey().CleanKey(); //loads private Key string (Format -----BEGIN PRIVATE KEY-----) and removes header and footer
var key = ECDsa.Create();
key.ImportPkcs8PrivateKey(Convert.FromBase64String(privateKey), out _);
return key;
}