Class: WardenOpenidAuth::OpenidMetadata

Inherits:
Object
  • Object
show all
Includes:
ERB::Util
Defined in:
lib/warden_openid_auth/openid_metadata.rb

Overview

Representation of the OpenID config document.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: WardenOpenidAuth.config) ⇒ OpenidMetadata

Returns a new instance of OpenidMetadata.

Parameters:

  • config (#openid_metadata_url, #cache, #cache_options) (defaults to: WardenOpenidAuth.config)

    object containg the desired configuration.



16
17
18
19
20
21
# File 'lib/warden_openid_auth/openid_metadata.rb', line 16

def initialize(config: WardenOpenidAuth.config)
  @metadata_url = config.
  @cache = config.cache
  @cache_options = config.cache_options
  @client_id = config.client_id
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object

Check if the method asked for is a key in the config_document. If it is return it. Otherwise call parent which will throw a NoMethodError error.



38
39
40
# File 'lib/warden_openid_auth/openid_metadata.rb', line 38

def method_missing(name)
  config_document.fetch(name.to_s) { super }
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



13
14
15
# File 'lib/warden_openid_auth/openid_metadata.rb', line 13

def cache
  @cache
end

#cache_optionsObject (readonly)

Returns the value of attribute cache_options.



13
14
15
# File 'lib/warden_openid_auth/openid_metadata.rb', line 13

def cache_options
  @cache_options
end

#client_idObject (readonly)

Returns the value of attribute client_id.



13
14
15
# File 'lib/warden_openid_auth/openid_metadata.rb', line 13

def client_id
  @client_id
end

#metadata_urlObject (readonly)

Returns the value of attribute metadata_url.



13
14
15
# File 'lib/warden_openid_auth/openid_metadata.rb', line 13

def 
  @metadata_url
end

Instance Method Details

#authorization_url(redirect_uri:, state:, scope: 'openid profile email') ⇒ String

Returns the full URL for authorization including parameters.

Returns:

  • (String)

    the full URL for authorization including parameters



24
25
26
27
28
29
# File 'lib/warden_openid_auth/openid_metadata.rb', line 24

def authorization_url(redirect_uri:, state:, scope: 'openid profile email')
  uri = URI(config_document['authorization_endpoint'])
  uri.query = "client_id=#{url_encode(client_id)}&redirect_uri=#{url_encode(redirect_uri)}" \
              "&scope=#{url_encode(scope)}&state=#{url_encode(state)}&response_mode=query&response_type=code"
  uri.to_s
end

#respond_to_missing?(name) ⇒ Boolean

if the the object does not respond to the method passed to respond_to? Check if the method called is a key on config_document, if it is respond with true indicating that the object does respond to that method.

Returns:

  • (Boolean)


45
46
47
48
49
# File 'lib/warden_openid_auth/openid_metadata.rb', line 45

def respond_to_missing?(name)
  return true if config_document.include?(name.to_s)

  super
end

#to_hHash

Returns a hash representation of the OpenID configuration document.

Returns:

  • (Hash)

    a hash representation of the OpenID configuration document.



32
33
34
# File 'lib/warden_openid_auth/openid_metadata.rb', line 32

def to_h
  config_document
end