public class AuthenticationToken extends Object
An authentication token (or "provider authentication token" or "provider token" in Apple's terminology) is a JSON Web Token (JWT) that contains cryptographically-signed claims about the identity of the sender that can be used by APNs clients in lieu of mutual TLS authentication to authenticate with an APNs server. Authentication tokens contain "claims" that identify the development team sending push notifications as well as the specific key used to sign the token.
When clients use token-based authentication, they send an authentication token with each push notification. Tokens
may expire, in which case clients must discard the old token and generate a new one. Callers generally do
not need to interact with authentication tokens directly; ApnsClient
instances
using token-based authentication will manage authentication tokens automatically.
Tokens may be constructed from an ApnsSigningKey
(for clients sending notifications) or from a
Base64-encoded JWT string (for servers verifying a token from a client).
Constructor and Description |
---|
AuthenticationToken(ApnsSigningKey signingKey,
Date issuedAt)
Constructs a new authentication token using the given signing key (and associated metadata) issued at the given
date.
|
AuthenticationToken(String base64EncodedToken)
Constructs a new authentication token from a Base64-encoded JWT string.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
AsciiString |
getAuthorizationHeader()
Returns a complete APNs authorization header value (i.e.
|
Date |
getIssuedAt()
Returns the time at which this token was issued.
|
String |
getKeyId()
Returns the Apple-issued ID of the key used to sign this token.
|
String |
getTeamId()
Returns the Apple-issued ID of the team to which this authentication token's key pair belongs.
|
int |
hashCode() |
String |
toString()
Returns a Base64-encoded JWT representation of this authentication token.
|
boolean |
verifySignature(ApnsVerificationKey verificationKey)
Verifies the cryptographic signature of this authentication token.
|
public AuthenticationToken(ApnsSigningKey signingKey, Date issuedAt) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException
signingKey
- the signing key from which to derive metadata and with which to sign the tokenissuedAt
- the time at which the token was issuedNoSuchAlgorithmException
- if the JVM doesn't support the
"SHA256withECDSA" algorithmInvalidKeyException
- if the given key was invalid for any reasonSignatureException
- if the given key could not be used to sign the tokenpublic AuthenticationToken(String base64EncodedToken)
base64EncodedToken
- a Base64-encoded JWT stringpublic Date getIssuedAt()
public String getKeyId()
public String getTeamId()
public boolean verifySignature(ApnsVerificationKey verificationKey) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException
verificationKey
- the verification key (public key) to be used to verify this token's signaturetrue
if this token's signature was verified or false
otherwiseNoSuchAlgorithmException
- if the JVM doesn't support the
"SHA256withECDSA" algorithmInvalidKeyException
- if the given key was invalid for any reasonSignatureException
- if the given key could not be used to verify the token's signaturepublic AsciiString getAuthorizationHeader()
public String toString()
Copyright © 2013–2018 Turo. All rights reserved.