Class: Devise::Passwordless::SignedGlobalIDTokenizer

Inherits:
Object
  • Object
show all
Defined in:
lib/devise/passwordless/tokenizers/signed_global_id_tokenizer.rb

Class Method Summary collapse

Class Method Details

.decode(token, resource_class) ⇒ Object

Raises:



13
14
15
16
17
18
# File 'lib/devise/passwordless/tokenizers/signed_global_id_tokenizer.rb', line 13

def self.decode(token, resource_class)
  resource = GlobalID::Locator.locate_signed(token, for: "login")
  raise ExpiredTokenError unless resource
  raise InvalidTokenError if resource.class != resource_class
  [resource, {}]
end

.encode(resource, expires_in: nil, expires_at: nil) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/devise/passwordless/tokenizers/signed_global_id_tokenizer.rb', line 5

def self.encode(resource, expires_in: nil, expires_at: nil)
  if expires_at
    resource.to_sgid(expires_at: expires_at, for: "login").to_s
  else
    resource.to_sgid(expires_in: expires_in || resource.class., for: "login").to_s
  end
end