Class: Layer::IdentityToken

Inherits:
Object
  • Object
show all
Defined in:
lib/layer/identity_token.rb,
lib/layer/identity_token/version.rb

Constant Summary collapse

SUPPORTED_CLAIM_ATTRIBUTES =
%w(first_name last_name display_name avatar_url metadata)
VERSION =
"0.3.0"

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id, nonce, expires_at = (Time.now+(86400*14)), more_claim_attributes = {}) ⇒ IdentityToken

Returns a new instance of IdentityToken.



30
31
32
33
34
35
36
37
38
# File 'lib/layer/identity_token.rb', line 30

def initialize(user_id, nonce, expires_at = (Time.now+(86400*14)),
               more_claim_attributes = {})
  @user_id = user_id
  @nonce = nonce
  @expires_at = expires_at
  @more_claim_attributes = more_claim_attributes.select do |key, _value|
    SUPPORTED_CLAIM_ATTRIBUTES.include?(key.to_s)
  end
end

Class Attribute Details

.layer_key_idObject



14
15
16
# File 'lib/layer/identity_token.rb', line 14

def layer_key_id
  @layer_key_id || ENV["LAYER_KEY_ID"]
end

.layer_private_keyObject



18
19
20
# File 'lib/layer/identity_token.rb', line 18

def layer_private_key
  @layer_private_key || ENV["LAYER_PRIVATE_KEY"]
end

.layer_provider_idObject



10
11
12
# File 'lib/layer/identity_token.rb', line 10

def layer_provider_id
  @layer_provider_id || ENV["LAYER_PROVIDER_ID"]
end

Instance Attribute Details

#expires_atObject (readonly)

Returns the value of attribute expires_at.



25
26
27
# File 'lib/layer/identity_token.rb', line 25

def expires_at
  @expires_at
end

#more_claim_attributesObject (readonly)

Returns the value of attribute more_claim_attributes.



25
26
27
# File 'lib/layer/identity_token.rb', line 25

def more_claim_attributes
  @more_claim_attributes
end

#nonceObject (readonly)

Returns the value of attribute nonce.



25
26
27
# File 'lib/layer/identity_token.rb', line 25

def nonce
  @nonce
end

#user_idObject (readonly)

Returns the value of attribute user_id.



25
26
27
# File 'lib/layer/identity_token.rb', line 25

def user_id
  @user_id
end

Instance Method Details

#as_json(options = {}) ⇒ Object



44
45
46
# File 'lib/layer/identity_token.rb', line 44

def as_json(options = {})
  encode
end

#encodeObject Also known as: to_s



40
41
42
# File 'lib/layer/identity_token.rb', line 40

def encode
  JWT.encode(claim, private_key, "RS256", headers)
end