Parent

Files

Merb::Authentication::Strategies::Basic::OpenID

Public Instance Methods

customize_openid_request!(openid_request) click to toggle source

Overwrite this to add extra options to the OpenID request before it is made.

@example request.return_to_args = 1 # remember_me=1 is added when returning from the OpenID provider.

@api overwritable

# File lib/merb-auth-more/strategies/basic/openid.rb, line 68
def customize_openid_request!(openid_request)
end
find_user_by_identity_url(url) click to toggle source

Overwrite this to support an ORM other than DataMapper

@api overwritable

# File lib/merb-auth-more/strategies/basic/openid.rb, line 134
def find_user_by_identity_url(url)
  user_class.first(:identity_url => url)
end
on_cancel!(response) click to toggle source

@api overwritable

# File lib/merb-auth-more/strategies/basic/openid.rb, line 113
def on_cancel!(response)
  request.session.authentication.errors.clear!
  request.session.authentication.errors.add(:openid, 'OpenID rejected our request')
  nil
end
on_failure!(response) click to toggle source

Overwrite the on_failure! method with the required behavior for failed logins

@api overwritable

# File lib/merb-auth-more/strategies/basic/openid.rb, line 97
def on_failure!(response)
  session.authentication.errors.clear!
  session.authentication.errors.add(:openid, 'OpenID verification failed, maybe the provider is down? Or the session timed out')
  nil
end
on_setup_needed!(response) click to toggle source

@api overwritable

# File lib/merb-auth-more/strategies/basic/openid.rb, line 105
def on_setup_needed!(response)
  request.session.authentication.errors.clear!
  request.session.authentication.errors.add(:openid, 'OpenID does not seem to be configured correctly')
  nil
end
on_success!(response, sreg_response) click to toggle source

Overwrite the on_success! method with the required behavior for successful logins

@api overwritable

# File lib/merb-auth-more/strategies/basic/openid.rb, line 82
def on_success!(response, sreg_response)
  if user = find_user_by_identity_url(response.identity_url)
    user
  else
    request.session[:'openid.url'] = response.identity_url
    required_reg_fields.each do |f|
      session[:"openid.#{f}"] = sreg_response.data[f] if sreg_response.data[f]
    end if sreg_response
    redirect!(Merb::Router.url(:signup))
  end
end
openid_callback_url() click to toggle source

Used to define the callback url for the openid provider. By default it is set to the named :openid route.

@api overwritable

# File lib/merb-auth-more/strategies/basic/openid.rb, line 75
def openid_callback_url
  "#{request.protocol}://#{request.host}#{Merb::Router.url(:openid)}"
end
openid_store() click to toggle source

Overwrite this method to set your store

@api overwritable

# File lib/merb-auth-more/strategies/basic/openid.rb, line 141
def openid_store
  ::OpenID::Store::Filesystem.new("#{Merb.root}/tmp/openid")
end
optional_reg_fields() click to toggle source

@api overwritable

# File lib/merb-auth-more/strategies/basic/openid.rb, line 127
def optional_reg_fields
  ['fullname']
end
required_reg_fields() click to toggle source

@api overwritable

# File lib/merb-auth-more/strategies/basic/openid.rb, line 121
def required_reg_fields
  ['nickname', 'email']
end
run!() click to toggle source
# File lib/merb-auth-more/strategies/basic/openid.rb, line 29
def run!
  if request.params[:'openid.mode']
    response = consumer.complete(request.send(:query_params), "#{request.protocol}://#{request.host}" + request.path)
    case response.status.to_s
    when 'success'
      sreg_response = ::OpenID::SReg::Response.from_success_response(response)
      result = on_success!(response, sreg_response)
      Merb.logger.info "\n\n#{result.inspect}\n\n"
      result
    when 'failure'
      on_failure!(response)
    when  'setup_needed'
      on_setup_needed!(response)
    when 'cancel'
      on_cancel!(response)
    end
  elsif identity_url = params[:openid_url]
    begin
      openid_request = consumer.begin(identity_url)
      openid_reg = ::OpenID::SReg::Request.new
      openid_reg.request_fields(required_reg_fields, true)
      openid_reg.request_fields(optional_reg_fields)
      openid_request.add_extension(openid_reg)
      customize_openid_request!(openid_request)
      redirect!(openid_request.redirect_url("#{request.protocol}://#{request.host}", openid_callback_url))
    rescue ::OpenID::OpenIDError => e
      request.session.authentication.errors.clear!
      request.session.authentication.errors.add(:openid, 'The OpenID verification failed')
      nil
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.