apns ( http2 ) で Token Authentication を行う

apns ( http2 ) で新たに Token Authentication という jwt による認証機能が追加されました。 詳しい内容は下記にあります。

developer.apple.com

developer.apple.com

上にある通り、今までは証明書の期限切れという問題がありましたが、Token Authentication を行うと期限がありませんのでその問題から解放されます。 ただこれも説明にある通り、token (jwt) は1時間ほど有効なものなので、push 通知サーバ等が面倒を見る必要があります。

もう一点は利点と言えるかわかりませんが、下記の説明のように複数のアプリに使えます。

Get an authentication key to generate server-side tokens. You can use these tokens as an alternative to certificates for your notification requests. One authentication key can be used for multiple apps and does not expire.

以前 apnsapi という go のパッケージを作ったのでこちらに jwt で認証する機能を追加しました。

github.com

***.p8 というファイルを apple からダウンロードしたのちに

$ go run _example/main.go --key /path/to/file.p8 --kid $keyIdentifier --teamId $teamID --topic $topic --token $token

とすると試せます。