class Lorkhan::ProviderToken

Wrapper for creating the authentication token for communicating with Apple's servers.

See the “Provider Authentication Tokens” from Apple's “Local and Remote Notification Programming Guide” developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html#//apple_ref/doc/uid/TP40008194-CH11-SW1

Constants

ALGORITHM

Public Class Methods

new(key_id:, team_id:, secret:) click to toggle source

Create a new token

key_id: An alphanumeric string obtained from the developer portal. team_id: The team id for your developer account. Obtained from the developer portal. secret: The content of the Authentication Token key file obtained from the developer portal.

# File lib/lorkhan/provider_token.rb, line 21
def initialize(key_id:, team_id:, secret:)
  @key_id  = key_id
  @team_id = team_id
  @secret  = secret
end

Public Instance Methods

encode() click to toggle source
# File lib/lorkhan/provider_token.rb, line 27
def encode
  JWT.encode(payload, p_key, ALGORITHM, headers)
end

Private Instance Methods

headers() click to toggle source
# File lib/lorkhan/provider_token.rb, line 48
def headers
  {
    kid: @key_id
  }
end
p_key() click to toggle source
# File lib/lorkhan/provider_token.rb, line 33
def p_key
  @p_key ||= begin
    sec = OpenSSL::PKey::EC.new(@secret)
    sec.check_key
    sec
  end
end
payload() click to toggle source
# File lib/lorkhan/provider_token.rb, line 41
def payload
  {
    iss: @team_id,
    iat: Time.now.utc.to_i
  }
end