Class | CASServer::Authenticators::Google |
In: |
lib/casserver/authenticators/google.rb
|
Parent: | CASServer::Authenticators::Base |
# File lib/casserver/authenticators/google.rb, line 11 11: def validate(credentials) 12: read_standard_credentials(credentials) 13: 14: return false if @username.blank? || @password.blank? 15: 16: auth_data = { 17: 'Email' => @username, 18: 'Passwd' => @password, 19: 'service' => 'xapi', 20: 'source' => 'RubyCAS-Server', 21: 'accountType' => 'HOSTED_OR_GOOGLE' 22: } 23: 24: url = URI.parse('https://www.google.com/accounts/ClientLogin') 25: if @options[:proxy] 26: http = Net::HTTP.Proxy(@options[:proxy][:host], @options[:proxy][:port], @options[:proxy][:username], @options[:proxy][:password]).new(url.host, url.port) 27: else 28: http = Net::HTTP.new(url.host, url.port) 29: end 30: http.use_ssl = true 31: 32: # TODO: make the timeout configurable 33: wait_seconds = 10 34: begin 35: timeout(wait_seconds) do 36: res = http.start do |conn| 37: req = Net::HTTP::Post.new(url.path) 38: req.set_form_data(auth_data,'&') 39: conn.request(req) 40: end 41: 42: case res 43: when Net::HTTPSuccess 44: true 45: when Net::HTTPForbidden 46: false 47: else 48: $LOG.error("Unexpected response from Google while validating credentials: #{res.inspect} ==> #{res.body}.") 49: raise CASServer::AuthenticatorError, "Unexpected response received from Google while validating credentials." 50: end 51: end 52: rescue Timeout::Error 53: $LOG.error("Google did not respond to the credential validation request. We waited for #{wait_seconds.inspect} seconds before giving up.") 54: raise CASServer::AuthenticatorError, "Timeout while waiting for Google to validate credentials." 55: end 56: 57: end