Class: AzureJwtAuth::JwtManager
- Inherits:
-
Object
- Object
- AzureJwtAuth::JwtManager
- Defined in:
- lib/azure_jwt_auth/jwt_manager.rb
Class Attribute Summary collapse
-
.providers ⇒ Object
readonly
Returns the value of attribute providers.
Class Method Summary collapse
Instance Method Summary collapse
-
#custom_valid? ⇒ Boolean
Check custom validations defined into provider.
- #header ⇒ Object
-
#initialize(request, provider_id) ⇒ JwtManager
constructor
A new instance of JwtManager.
-
#iss_valid? ⇒ Boolean
Validates issuer.
- #payload ⇒ Object
-
#valid? ⇒ Boolean
Validates the payload hash for expiration and meta claims.
Constructor Details
#initialize(request, provider_id) ⇒ JwtManager
Returns a new instance of JwtManager.
20 21 22 23 24 25 26 |
# File 'lib/azure_jwt_auth/jwt_manager.rb', line 20 def initialize(request, provider_id) raise NotAuthorizationHeader unless request.env['HTTP_AUTHORIZATION'] raise ProviderNotFound unless (@provider = self.class.find_provider(provider_id)) @jwt = request.env['HTTP_AUTHORIZATION'].split.last # remove Bearer @jwt_info = JWT.decode(@jwt, nil, false) end |
Class Attribute Details
.providers ⇒ Object (readonly)
Returns the value of attribute providers.
7 8 9 |
# File 'lib/azure_jwt_auth/jwt_manager.rb', line 7 def providers @providers end |
Class Method Details
.find_provider(uid) ⇒ Object
14 15 16 17 |
# File 'lib/azure_jwt_auth/jwt_manager.rb', line 14 def find_provider(uid) return unless @providers @providers[uid] end |
Instance Method Details
#custom_valid? ⇒ Boolean
Check custom validations defined into provider
43 44 45 46 47 48 49 |
# File 'lib/azure_jwt_auth/jwt_manager.rb', line 43 def custom_valid? @provider.validations.each do |key, value| return false unless payload[key] == value end true end |
#header ⇒ Object
32 33 34 |
# File 'lib/azure_jwt_auth/jwt_manager.rb', line 32 def header @jwt_info ? @jwt_info.last : nil end |
#iss_valid? ⇒ Boolean
Validates issuer
37 38 39 40 |
# File 'lib/azure_jwt_auth/jwt_manager.rb', line 37 def iss_valid? payload['iss'] == @provider.config['issuer'] || # b2c (payload['tid'] && @provider.config['issuer'] =~ /#{payload['tid']}/) # ac end |
#payload ⇒ Object
28 29 30 |
# File 'lib/azure_jwt_auth/jwt_manager.rb', line 28 def payload @jwt_info ? @jwt_info.first : nil end |
#valid? ⇒ Boolean
Validates the payload hash for expiration and meta claims
52 53 54 |
# File 'lib/azure_jwt_auth/jwt_manager.rb', line 52 def valid? payload && iss_valid? && custom_valid? && rsa_decode end |