Class: QuizApiClient::Services::JwtService
- Inherits:
-
Object
- Object
- QuizApiClient::Services::JwtService
- Defined in:
- lib/quiz_api_client/services/jwt_service.rb
Constant Summary collapse
- HASHING_ALGORITHM =
'HS512'.freeze
Instance Attribute Summary collapse
-
#consumer_key ⇒ Object
readonly
Returns the value of attribute consumer_key.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#shared_secret ⇒ Object
readonly
Returns the value of attribute shared_secret.
Instance Method Summary collapse
- #grant_permission(scope:, exp: nil, uuid: nil, **additional_fields) ⇒ Object
-
#initialize(consumer_key: nil, consumer_request_id: nil, shared_secret:, host:, protocol: 'https') ⇒ JwtService
constructor
A new instance of JwtService.
Constructor Details
#initialize(consumer_key: nil, consumer_request_id: nil, shared_secret:, host:, protocol: 'https') ⇒ JwtService
Returns a new instance of JwtService.
7 8 9 10 11 12 13 |
# File 'lib/quiz_api_client/services/jwt_service.rb', line 7 def initialize(consumer_key: nil, consumer_request_id: nil, shared_secret:, host:, protocol: 'https') @consumer_key = consumer_key @host = host @shared_secret = shared_secret @protocol = protocol @consumer_request_id = consumer_request_id end |
Instance Attribute Details
#consumer_key ⇒ Object (readonly)
Returns the value of attribute consumer_key.
5 6 7 |
# File 'lib/quiz_api_client/services/jwt_service.rb', line 5 def consumer_key @consumer_key end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
5 6 7 |
# File 'lib/quiz_api_client/services/jwt_service.rb', line 5 def host @host end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
5 6 7 |
# File 'lib/quiz_api_client/services/jwt_service.rb', line 5 def protocol @protocol end |
#shared_secret ⇒ Object (readonly)
Returns the value of attribute shared_secret.
5 6 7 |
# File 'lib/quiz_api_client/services/jwt_service.rb', line 5 def shared_secret @shared_secret end |
Instance Method Details
#grant_permission(scope:, exp: nil, uuid: nil, **additional_fields) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/quiz_api_client/services/jwt_service.rb', line 15 def (scope:, exp: nil, uuid: nil, **additional_fields) payload = { host: URI.parse("#{protocol}://#{host}").host, consumer_key: consumer_key, scope: scope, exp: exp || Time.now.utc.to_i + 60, **additional_fields } if uuid payload[:user] ||= {} payload[:user][:uuid] = uuid end JWT.encode(payload, shared_secret, HASHING_ALGORITHM) end |