Support for Pushsharp Apple Key authentication push notification

Does pushsharp support Apple's new approach for sending APNs using the Apple Authentication Key (which never expires) instead of using certificates? Can I use it with pushsharp? If not, is there another C # library to support it?

+6
source share
2 answers

here you are:

private string GetToken() { var algorithm = "ES256"; var teamID = "teamID"; var apnsKeyID = "apnsKeyID"; var apnsAuthKeyPath = @"apnsAuthKeyPath"; var epochNow = DateTimeOffset.Now.ToUnixTimeSeconds(); var header = new Dictionary<string, object>() { { "alg", algorithm }, { "kid" , apnsKeyID } }; var payload = new Dictionary<string, object>() { { "iss", teamID }, { "iat", epochNow } }; var privateKey = GetPrivateKey(apnsAuthKeyPath); var token = Jose.JWT.Encode(payload, privateKey, algorithm: Jose.JwsAlgorithm.ES256, extraHeaders: header); return token; } private CngKey GetPrivateKey(string apnsAuthKey) { using (var reader = File.OpenText(apnsAuthKey)) { var ecPrivateKeyParameters = (ECPrivateKeyParameters)new PemReader(reader).ReadObject(); var x = ecPrivateKeyParameters.Parameters.G.AffineXCoord.GetEncoded(); var y = ecPrivateKeyParameters.Parameters.G.AffineYCoord.GetEncoded(); var d = ecPrivateKeyParameters.D.ToByteArrayUnsigned(); return EccKey.New(x, y, d); } } 

then you can just call the submit method in apns.

+1
source

Where should we place this code?

0
source

Source: https://habr.com/ru/post/1264423/


All Articles