Class: Pusher::PushNotifications::Token

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pusher/push_notifications/token.rb

Instance Method Summary collapse

Constructor Details

#initialize(config: PushNotifications) ⇒ Token

Returns a new instance of Token.



9
10
11
# File 'lib/pusher/push_notifications/token.rb', line 9

def initialize(config: PushNotifications)
  @config = config
end

Instance Method Details

#generate(user) ⇒ Object



13
14
15
16
17
18
# File 'lib/pusher/push_notifications/token.rb', line 13

def generate(user)
  exp = Time.now.to_i + 24 * 60 * 60 # Current time + 24h
  iss = "https://#{instance_id}.pushnotifications.pusher.com"
  payload = { 'sub' => user, 'exp' => exp, 'iss' => iss }
  JWT.encode payload, secret_key, 'HS256'
end