Class: KindeSdk::Client

Inherits:
Object
  • Object
show all
Includes:
FeatureFlags, Permissions
Defined in:
lib/kinde_sdk/client.rb,
lib/kinde_sdk/client/permissions.rb,
lib/kinde_sdk/client/feature_flags.rb

Defined Under Namespace

Modules: FeatureFlags, Permissions

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Permissions

#get_permission, #get_permissions, #permission_granted?

Methods included from FeatureFlags

#get_boolean_flag, #get_flag, #get_integer_flag, #get_string_flag

Constructor Details

#initialize(sdk_api_client, tokens_hash) ⇒ Client



10
11
12
13
# File 'lib/kinde_sdk/client.rb', line 10

def initialize(sdk_api_client, tokens_hash)
  @kinde_api_client = sdk_api_client
  set_hash_related_data(tokens_hash)
end

Instance Attribute Details

#bearer_tokenObject

Returns the value of attribute bearer_token.



8
9
10
# File 'lib/kinde_sdk/client.rb', line 8

def bearer_token
  @bearer_token
end

#expires_atObject

Returns the value of attribute expires_at.



8
9
10
# File 'lib/kinde_sdk/client.rb', line 8

def expires_at
  @expires_at
end

#kinde_api_clientObject

Returns the value of attribute kinde_api_client.



8
9
10
# File 'lib/kinde_sdk/client.rb', line 8

def kinde_api_client
  @kinde_api_client
end

#tokens_hashObject

Returns the value of attribute tokens_hash.



8
9
10
# File 'lib/kinde_sdk/client.rb', line 8

def tokens_hash
  @tokens_hash
end

Instance Method Details

#get_claim(claim, token_type = :access_token) ⇒ Hash

token_type is one of: :access_token, :id_token

Examples:

“scp”, value: [“openid”, “offline”]




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

def get_claim(claim, token_type = :access_token)
  token = tokens_hash[token_type]
  return unless token

  value = JWT.decode(token, nil, false)[0][claim]
  return unless value

  { name: claim, value: value }
end

#refresh_tokenObject



19
20
21
22
23
24
# File 'lib/kinde_sdk/client.rb', line 19

def refresh_token
  new_tokens_hash = KindeSdk.refresh_token(tokens_hash)
  set_hash_related_data(new_tokens_hash)
  @kinde_api_client = KindeSdk.api_client(tokens_hash["access_token"])
  new_tokens_hash
end

#token_expired?Boolean



15
16
17
# File 'lib/kinde_sdk/client.rb', line 15

def token_expired?
  expires_at.to_i > 0 && (expires_at <= Time.now.to_i)
end