Class: Ghost::Authentication::JwtToken

Inherits:
Object
  • Object
show all
Defined in:
lib/ghost/authentication/jwt_token.rb

Constant Summary collapse

TOKEN_EXPIRY =

5 minutes

300
REFRESH_BUFFER =

refresh 1 minute before expiry

60

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ JwtToken

Returns a new instance of JwtToken.

Raises:



11
12
13
14
15
16
17
18
19
# File 'lib/ghost/authentication/jwt_token.rb', line 11

def initialize(key)
  parts = key.to_s.split(":")
  raise Ghost::Error, "Admin API key must be in format {id}:{secret}" unless parts.length == 2

  @id = parts[0]
  @secret = [parts[1]].pack("H*")
  @token = nil
  @expires_at = nil
end

Instance Method Details

#apply(request) ⇒ Object



21
22
23
# File 'lib/ghost/authentication/jwt_token.rb', line 21

def apply(request)
  request.headers["Authorization"] = "Ghost #{token}"
end