Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/authlogic_connect/ext.rb
Overview
these are extensions I’ve found useful for this project
Instance Method Summary collapse
-
#normalize_identifier ⇒ Object
normalizes an OpenID according to openid.net/specs/openid-authentication-2_0.html#normalization.
Instance Method Details
#normalize_identifier ⇒ Object
normalizes an OpenID according to openid.net/specs/openid-authentication-2_0.html#normalization
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 |