Skip to content

Commit 8d55eb2

Browse files
committed
Add JWT token auth docs
1 parent 3afa5a2 commit 8d55eb2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,34 @@ func main() {
6868
}
6969
```
7070

71+
## JWT Token Example
72+
73+
Instead of using a `.p12` or `.pem` certificate as above, you can optionally use
74+
APNs JWT _Provider Authentication Tokens_. First you will need a signing key (`.p8` file), Key ID and Team ID [from Apple](http://help.apple.com/xcode/mac/current/#/dev54d690a66). Once you have these details, you can create a new client:
75+
76+
```go
77+
authKey, err := token.AuthKeyFromFile("../AuthKey_XXX.p8")
78+
if err != nil {
79+
log.Fatal("token error:", err)
80+
}
81+
82+
token := &token.Token{
83+
AuthKey: authKey,
84+
// KeyID from developer account (Certificates, Identifiers & Profiles -> Keys)
85+
KeyID: "ABC123DEFG",
86+
// TeamID from developer account (View Account -> Membership)
87+
TeamID: "DEF123GHIJ",
88+
}
89+
...
90+
91+
client := apns2.NewTokenClient(token)
92+
res, err := client.Push(notification)
93+
```
94+
95+
- You can use one APNs signing key to authenticate tokens for multiple apps.
96+
- A signing key works for both the development and production environments.
97+
- A signing key doesn’t expire but can be revoked.
98+
7199
## Notification
72100

73101
At a minimum, a _Notification_ needs a _DeviceToken_, a _Topic_ and a _Payload_.

0 commit comments

Comments
 (0)