Class: KindeSdk::Client
- Inherits:
-
Object
- Object
- KindeSdk::Client
- 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
-
#auto_refresh_tokens ⇒ Object
Returns the value of attribute auto_refresh_tokens.
-
#kinde_api_client ⇒ Object
Returns the value of attribute kinde_api_client.
-
#token_store ⇒ Object
Returns the value of attribute token_store.
Instance Method Summary collapse
-
#bearer_token ⇒ String
Returns the bearer token for backwards compatibility.
-
#expires_at ⇒ Integer
Returns the token expiration time for backwards compatibility.
-
#get_claim(claim, token_type = :access_token) ⇒ Hash
token_type is one of: :access_token, :id_token.
-
#initialize(sdk_api_client, tokens_hash, auto_refresh_tokens) ⇒ Client
constructor
A new instance of Client.
- #refresh_token ⇒ Object
- #token_expired? ⇒ Boolean
-
#tokens_hash ⇒ Hash
Returns the tokens hash for backwards compatibility.
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, auto_refresh_tokens) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 |
# File 'lib/kinde_sdk/client.rb', line 13 def initialize(sdk_api_client, tokens_hash, auto_refresh_tokens) @kinde_api_client = sdk_api_client @auto_refresh_tokens = auto_refresh_tokens @token_store = TokenManager.create_store(tokens_hash) # refresh the token if it's expired and auto_refresh_tokens is enabled refresh_token if auto_refresh_tokens && TokenManager.token_expired?(@token_store) end |
Instance Attribute Details
#auto_refresh_tokens ⇒ Object
Returns the value of attribute auto_refresh_tokens.
11 12 13 |
# File 'lib/kinde_sdk/client.rb', line 11 def auto_refresh_tokens @auto_refresh_tokens end |
#kinde_api_client ⇒ Object
Returns the value of attribute kinde_api_client.
11 12 13 |
# File 'lib/kinde_sdk/client.rb', line 11 def kinde_api_client @kinde_api_client end |
#token_store ⇒ Object
Returns the value of attribute token_store.
11 12 13 |
# File 'lib/kinde_sdk/client.rb', line 11 def token_store @token_store end |
Instance Method Details
#bearer_token ⇒ String
Returns the bearer token for backwards compatibility
24 25 26 |
# File 'lib/kinde_sdk/client.rb', line 24 def bearer_token @token_store.bearer_token end |
#expires_at ⇒ Integer
Returns the token expiration time for backwards compatibility
36 37 38 |
# File 'lib/kinde_sdk/client.rb', line 36 def expires_at @token_store.expires_at end |
#get_claim(claim, token_type = :access_token) ⇒ Hash
token_type is one of: :access_token, :id_token
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/kinde_sdk/client.rb', line 57 def get_claim(claim, token_type = :access_token) refresh_token if auto_refresh_tokens && token_expired? token = @token_store.tokens[token_type.to_sym] return unless token value = JWT.decode(token, nil, false)[0][claim] return unless value { name: claim, value: value } end |
#refresh_token ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/kinde_sdk/client.rb', line 44 def refresh_token new_tokens_hash = TokenManager.refresh_tokens(@token_store, Current.session) return nil unless new_tokens_hash @token_store.set_tokens(new_tokens_hash) @kinde_api_client = KindeSdk.api_client(@token_store.bearer_token) new_tokens_hash end |
#token_expired? ⇒ Boolean
40 41 42 |
# File 'lib/kinde_sdk/client.rb', line 40 def token_expired? TokenManager.token_expired?(@token_store) end |
#tokens_hash ⇒ Hash
Returns the tokens hash for backwards compatibility
30 31 32 |
# File 'lib/kinde_sdk/client.rb', line 30 def tokens_hash @token_store.tokens end |