class OpenIDConnect::Client::Registrar
Public Class Methods
new(endpoint, attributes = {})
click to toggle source
# File lib/openid_connect/client/registrar.rb, line 62 def initialize(endpoint, attributes = {}) self.endpoint = endpoint self.initial_access_token = attributes[:initial_access_token] self.class.metadata_attributes.each do |_attr_| self.send "#{_attr_}=", attributes[_attr_] end end
Public Instance Methods
as_json(options = {})
click to toggle source
# File lib/openid_connect/client/registrar.rb, line 89 def as_json(options = {}) validate! self.class.metadata_attributes.inject({}) do |hash, _attr_| value = self.send _attr_ hash.merge! _attr_ => value unless value.nil? hash end end
read()
click to toggle source
# File lib/openid_connect/client/registrar.rb, line 104 def read # TODO: Do we want this feature even if we don't have rotate secret nor update metadata support? end
register!()
click to toggle source
# File lib/openid_connect/client/registrar.rb, line 98 def register! handle_response do http_client.post endpoint, to_json, 'Content-Type' => 'application/json' end end
sector_identifier()
click to toggle source
# File lib/openid_connect/client/registrar.rb, line 70 def sector_identifier if valid_uri?(sector_identifier_uri) URI.parse(sector_identifier_uri).host else hosts = redirect_uris.collect do |redirect_uri| if valid_uri?(redirect_uri, nil) URI.parse(redirect_uri).host else nil end end.compact.uniq if hosts.size == 1 hosts.first else nil end end end
validate!()
click to toggle source
# File lib/openid_connect/client/registrar.rb, line 108 def validate! valid? or raise ValidationFailed.new(self) end
Private Instance Methods
handle_error_response(response)
click to toggle source
# File lib/openid_connect/client/registrar.rb, line 181 def handle_error_response(response) raise RegistrationFailed.new(response.status, 'Client Registration Failed', response) end
handle_response() { || ... }
click to toggle source
# File lib/openid_connect/client/registrar.rb, line 162 def handle_response response = yield case response.status when 200..201 handle_success_response response else handle_error_response response end end
handle_success_response(response)
click to toggle source
# File lib/openid_connect/client/registrar.rb, line 172 def handle_success_response(response) credentials = response.body.with_indifferent_access Client.new( identifier: credentials[:client_id], secret: credentials[:client_secret], expires_in: credentials[:expires_in] ) end
http_client()
click to toggle source
# File lib/openid_connect/client/registrar.rb, line 149 def http_client case initial_access_token when nil OpenIDConnect.http_client when Rack::OAuth2::AccessToken::Bearer initial_access_token else Rack::OAuth2::AccessToken::Bearer.new( access_token: initial_access_token ) end end
sector_identifier_required?()
click to toggle source
# File lib/openid_connect/client/registrar.rb, line 114 def sector_identifier_required? subject_type.to_s == 'pairwise' && sector_identifier.blank? end
valid_uri?(uri, schemes = ['http', 'https'])
click to toggle source
# File lib/openid_connect/client/registrar.rb, line 119 def valid_uri?(uri, schemes = ['http', 'https']) # NOTE: specify nil for schemes to allow any schemes URI::DEFAULT_PARSER.make_regexp(schemes).match(uri).present? end
validate_contacts()
click to toggle source
# File lib/openid_connect/client/registrar.rb, line 124 def validate_contacts if contacts include_invalid = contacts.any? do |contact| begin mail = Mail::Address.new(contact) mail.address != contact || mail.domain.split(".").length <= 1 rescue :invalid end end errors.add :contacts, 'includes invalid email' if include_invalid end end
validate_plural_uri_attributes()
click to toggle source
# File lib/openid_connect/client/registrar.rb, line 138 def validate_plural_uri_attributes self.class.plural_uri_attributes.each do |_attr_| if (uris = self.send(_attr_)) include_invalid = uris.any? do |uri| !valid_uri?(uri, nil) end errors.add _attr_, 'includes invalid URL' if include_invalid end end end