Apple Push Notificações - Token Based Conexões para APNs (Part 3/4)

· Recursos

In this blog I will show how configure o sgcWebSockets JWT Client para enviar authenticated HTTP/2 requests para Apple Push Notificação Servers.

Secure your communications com serviço Apple Push Notificação (APNs) por using stateless autenticação Tokens.

Primeiro você deve obtain um Encryption Key e um Key ID um partir de Apple Developer Account. Once um bem-sucedido registration, você vai obtain um 10-Character string com o Key ID e um Autenticação Token signing key como um .p8 file extension.

Você deve use o sgcWebSockets JWT Client to generate um JWT using ES256 como algorithm. The token must not be generated para every HTTP/2 request, o token must not be refreshed before 20 minutes e not after 60 minutes.

Configurar JWT Client 

Configurar o JWT Client com o following values:

Using Token-Based conexões, requer para enviar o apns-topic com o valor de your app's bundle ID/app id (exemplo: com.exemplo.application).

oHTTP := TsgcHTTP2Client.Create(nil);
oHTTP.TLSOptions.IOHandler := iohOpenSSL;
oJWT := TsgcHTTP_JWT_Client.Create(nil);
oHTTP.Authentication.Token.JWT := oJWT;
oJWT.JWTOptions.Header.alg := jwtES256;
oJWT.JWTOptions.Header.kid := 'apple key id';
oJWT.JWTOptions.Payload.iss := 'issuer';
oJWT.JWTOptions.Payload.iat := StrToInt64(GetDateTimeUnix(Now, False));
oJWT.JWTOptions.Algorithms.ES.PrivateKey.LoadFromFile('AuthKey_**.p8');
oJWT.JWTOptions.RefreshTokenAfter := 60*40;
oHTTP.Request.CustomHeaders.Clear;
oHTTP.Request.CustomHeaders.Add('apns-topic: com.example.application');