Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/authlogic_connect/ext.rb

Overview

these are extensions I’ve found useful for this project

Instance Method Summary collapse

Instance Method Details

#normalize_identifierObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/authlogic_connect/ext.rb', line 4

def normalize_identifier
  # clean up whitespace
  identifier = self.dup.strip

  # if an XRI has a prefix, strip it.
  identifier.gsub!(/xri:\/\//i, '')

  # dodge XRIs -- TODO: validate, don't just skip.
  unless ['=', '@', '+', '$', '!', '('].include?(identifier.at(0))
    # does it begin with http?  if not, add it.
    identifier = "http://#{identifier}" unless identifier =~ /^http/i

    # strip any fragments
    identifier.gsub!(/\#(.*)$/, '')

    begin
      uri = URI.parse(identifier)
      uri.scheme = uri.scheme.downcase  # URI should do this
      identifier = uri.normalize.to_s
    rescue URI::InvalidURIError
      raise InvalidOpenId.new("#{identifier} is not an OpenID identifier")
    end
  end

  return identifier
end