Class: Virgil::Jwt::CallbackJwtProvider

Inherits:
AccessTokenProvider show all
Defined in:
lib/virgil/jwt/callback_jwt_provider.rb

Overview

provides an opportunity to get access token using callback mechanism.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obtain_token_proc) ⇒ CallbackJwtProvider

Returns a new instance of CallbackJwtProvider.



45
46
47
48
# File 'lib/virgil/jwt/callback_jwt_provider.rb', line 45

def initialize(obtain_token_proc)
  Validation.check_type_argument!(Proc, obtain_token_proc)
  @obtain_access_token_proc = obtain_token_proc
end

Instance Attribute Details

#obtain_access_token_procObject (readonly)

Callback, that takes an instance of [TokenContext] and returns string representation of generated instance of [AccessToken]



43
44
45
# File 'lib/virgil/jwt/callback_jwt_provider.rb', line 43

def obtain_access_token_proc
  @obtain_access_token_proc
end

Instance Method Details

#get_token(token_context) ⇒ AccessToken

Gets access token.

Parameters:

Returns:



53
54
55
56
57
# File 'lib/virgil/jwt/callback_jwt_provider.rb', line 53

def get_token(token_context)
  Validation.check_type_argument!(TokenContext, token_context)
  jwt_str = @obtain_access_token_proc.call(token_context)
  Jwt.from(jwt_str)
end