이 블로그에서는 sgcWebSockets JWT 클라이언트를 설정해 Apple Push Notification 서버로 인증된 HTTP/2 요청을 보내는 방법을 보여드릴게요.
무상태 인증 토큰을 사용해 Apple Push Notification 서비스(APNs)와의 통신을 보호하세요.
먼저 다음을 얻어야 해요Encryption Key and a Key ID from Apple Developer Account. Once a successful registration, you will obtain a 10-Character string with the Key ID and an Authentication Token signing key as a .p8 file extension.
You must use the sgcWebSockets JWT Client to generate a JWT using ES256 as algorithm. The token must not be generated for every HTTP/2 request, the token must not be refreshed before 20 minutes and not after 60 minutes.
Configure JWT Client
JWT 클라이언트를 다음 값으로 설정하세요.
- JWTOptions.Header.Algorithm: 토큰을 암호화하는 데 사용한 암호화 알고리즘이에요. APNs는 ES256 알고리즘만 지원해요.
- JWTOptions.Header.kid: 10자 키 IDbtained from your developer account.
- JWTOptions.Payload.iss: the value for which is the 10-character Team ID you use for developing your company's apps. Obtain this value from your developer account.
- JWTOptions.Payload.iat: The "issued at" time, whose value indicates the time at which this JSON token was generated. Specify the value as the number of seconds since Epoch, in UTC. The value must be no more than one hour from the current time.
- JWTOptions.RefreshTokenAfter: set the value in seconds to 40 minutes (60*40).
Using Token-Based connections, requires to send the apns-topic with the value of your app's bundle ID/app id (example: com.example.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');
