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:
- JWTOptions.Header.Algorithm: is o encryption algorithm you usado para encrypt o token. APNs suporta somente o ES256 algorithm.
- JWTOptions.Header.kid: is o 10-character Key ID obtained um partir de your developer account.
- JWTOptions.Payload.iss: o valor para which is o 10-character Team ID you use para developing your company's apps. Obtain this value um partir de your developer account.
- JWTOptions.Payload.iat: The "issued at" time, whose value indicates o time em which this JSON token was generated. Specify o valor como o number de seconds since Epoch, em UTC. The value deve ser no mais de one hour do current time.
- JWTOptions.RefreshTokenAfter: set o valor em seconds para 40 minutes (60*40).
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');
