Class: AzureJwtAuth::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/azure_jwt_auth/provider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uid, config_uri, validations = {}) ⇒ Provider

Returns a new instance of Provider.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/azure_jwt_auth/provider.rb', line 9

def initialize(uid, config_uri, validations={})
  @uid = uid
  @config_uri = config_uri
  @validations = validations

  begin
    @config = JSON.parse(Net::HTTP.get(URI(config_uri)))
  rescue JSON::ParserError
    raise InvalidProviderConfig, "config_uri response is not valid for provider: #{uid}"
  end

  load_keys
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/azure_jwt_auth/provider.rb', line 7

def config
  @config
end

#config_uriObject (readonly)

Returns the value of attribute config_uri.



6
7
8
# File 'lib/azure_jwt_auth/provider.rb', line 6

def config_uri
  @config_uri
end

#keysObject (readonly)

Returns the value of attribute keys.



7
8
9
# File 'lib/azure_jwt_auth/provider.rb', line 7

def keys
  @keys
end

#uidObject (readonly)

Returns the value of attribute uid.



6
7
8
# File 'lib/azure_jwt_auth/provider.rb', line 6

def uid
  @uid
end

#validationsObject (readonly)

Returns the value of attribute validations.



6
7
8
# File 'lib/azure_jwt_auth/provider.rb', line 6

def validations
  @validations
end

Instance Method Details

#load_keysObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/azure_jwt_auth/provider.rb', line 23

def load_keys
  uri = URI(@config['jwks_uri'])
  keys = JSON.parse(Net::HTTP.get(uri))['keys']

  @keys = {}
  keys.each do |key|
    cert = RsaPem.from(key['n'], key['e'])
    rsa = OpenSSL::PKey::RSA.new(cert)

    @keys[key['kid']] = rsa
  end
end