Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilJay committed May 29, 2019
2 parents d689f1b + 8e80361 commit db25ce8
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,51 @@
# APNJWT
Kotlin JWT implementation (Json Web Token) as required by APNs (Apple Push Notification Service)
Kotlin JWT implementation (Json Web Token) as required by APNs (Apple Push Notification Service), for use on Kotlin powered backend servers.

No other dependencies required.

## Sample Usage

Create required encoders, decoders and JSON Mapper (e.g. Gson or equivalent). These are later used to properly encode or decode the token header and payload.

```kotlin
val gson = GsonBuilder().create()

val mapper = object : Mapper {
override fun jsonString(header: JWTAuthHeader): String {
return gson.toJson(header, JWTAuthHeader::class.java)
}

override fun jsonString(payload: JWTAuthPayload): String {
return gson.toJson(payload, JWTAuthPayload::class.java)
}
}

val encoder = object : Base64Encoder {
override fun encode(bytes: ByteArray): String {
return Base64.encodeBase64String(bytes)
}
}

val decoder = object : Base64Decoder {
override fun decode(bytes: ByteArray): ByteArray {
return Base64.decodeBase64(bytes)
}
}
```

Create the token by providing the teamId, keyId and secret (private key excluding header and footer). The teamId can be obtained from the developer member center. The keyId can be obtained when you create your secret (private key).

```kotlin
val token = JWT.token("teamId", "keyId", "secret", mapper, encoder, decoder)
```

Include the token in the authentication header when you make yor push notification request to APNs:

```
'authentication' 'bearer $token'
```

## Documentation

For a detailed guide, please visit the [APNs documentation](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html#//apple_ref/doc/uid/TP40008194-CH8-SW1) page by Apple.

0 comments on commit db25ce8

Please sign in to comment.