Được TopGit lập chỉ mục từ metadata GitHub: PhilJay/JWT có 60 sao, viết chủ yếu bằng Kotlin. Kotlin JWT 🔑 implementation (Json Web Token) as required by APNs 🔔 (Apple Push Notifications) or Sign in with Apple 🍏
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Lightweight Kotlin JWT implementation (Json Web Token) designed for Apple, as required by APNs (Apple Push Notification Service) or Sign in with Apple (including JWT verification via JWK), for use on Kotlin powered backend servers. Eases the process of creating & verifying the token based on your credentials.
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.
val gson = GsonBuilder().create()
// generic JSON encoder
val jsonEncoder = object : JsonEncoder<JWTAuthHeader, JWTAuthPayload> {
override fun toJson(header: JWTAuthHeader): String {
return gson.toJson(header, JWTAuthHeader::class.java)
}
override fun toJson(payload: JWTAuthPayload): String {
return gson.toJson(payload, JWTAuthPayload::class.java)
}
}
// Base64 encoder using apache commons
private val encoder = object : Base64Encoder {
override fun encodeURLSafe(bytes: ByteArray): String {
return Base64.encodeBase64URLSafeString(bytes)
}
override fun encode(bytes: ByteArray): String {
return Base64.encodeBase64String(bytes)
}
}
// Base64 decoder using apache commons
private val decoder = object : Base64Decoder {
override fun decode(bytes: ByteArray): ByteArray {
return Base64.decodeBase64(bytes)
}
override fun decode(string: String): ByteArray {
return Base64.decodeBase64(string)
}
}
Create the Apple JWT token by providing your 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).
val token = JWT.tokenApple("teamId", "keyId", "secret", jsonEncoder, encoder, decoder)
Create any JWT token by providing the required algorithm, header, payload and secret (private key):
val header = JWTAuthHeader(...)
val payload = JWTAuthPayload(...)
val token = JWT.token(Algorithm.ES256, header, payload, "secret", jsonEncoder, encoder, decoder)
Decoding JWT
If you want to decode a JWT String, create a JSON decoder:
private val jsonDecoder = object : JsonDecoder<JWTAuthHeader, JWTAuthPayload> {
override fun headerFrom(json: String): JWTAuthHeader {
return gson.fromJson(json, JWTAuthHeader::class.java)
}
override fun payloadFrom(json: String): JWTAuthPayload {
return gson.fromJson(json, JWTAuthPayload::class.java)
}
}
Use the json decoder to decode your token String:
val tokenString = "ey..." // a valid JWT as a String
val t: JWTToken<JWTAuthHeader, JWTAuthPayload>? = JWT.decode(tokenString, jsonDecoder, decoder)
// conveniently access properties of the token...
val issuer = t?.payload?.iss
Verifying
In order to verify a JWT received from Sign in with Apple, securely transmit it to your backend, then obtain a JWK (Json Web Key) from Apple and use it as a public key for verification:
val jwk: JWKObject = ... // fetch current JWK (public key) from Apple endpoint
val tokenString = "ey..." // the token to validate / verify (obtained from Sign in with Apple)
// turns JWK into RSA public key, returns true if validation is successful
val valid = JWT.verify(tokenString, jwk, decoder)
Usage with APNs
Include the token in the authentication header when you make yor push notification request to APNs:
'authentication' 'bearer $token'
If you are sending pushes to iOS 13+ devices, also include the apns-push-type header:
'apns-push-type' 'alert' // possible values are 'alert' or 'background'
Documentation
For a detailed guide, please visit the APNs documentation page by Apple as well as the verifying users and generating tokens pages for Sign in with Apple. jwt.io is a good page for "debugging" tokens.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/PhilJay/JWT là nguồn chính thức.
PhilJay/JWT có bao nhiêu sao?
PhilJay/JWT có 60 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/PhilJay/JWT. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
PhilJay/JWT có những chủ đề gì?
GitHub topics của PhilJay/JWT: "apn", "apns", "apple", "apple-push-notifications", "json-web-token", "jwt", "jwt-authentication", "jwt-token". TopGit xếp repo vào nhóm Security.
PhilJay/JWT có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho PhilJay/JWT. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
PhilJay/JWT còn đang phát triển không?
Commit gần nhất trên PhilJay/JWT là 4.5 năm trước (theo timestamp GitHub). Repo có 9 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
PhilJay/JWT dùng license gì?
PhilJay/JWT phát hành theo license Apache-2.0. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
PhilJay/JWT viết bằng ngôn ngữ gì?
PhilJay/JWT chủ yếu viết bằng Kotlin. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về JWT?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về JWT.