1
0
Fork 0
forked from OpenNeo/impress
impress/lib/openneo-auth.rb

66 lines
1.8 KiB
Ruby
Raw Normal View History

2010-10-18 14:58:45 -07:00
require 'openneo-auth/session'
require 'openneo-auth/strategy'
2010-11-13 16:42:56 -08:00
Warden::Strategies.add :openneo_auth_token, Openneo::Auth::Strategies::Token
Warden::Strategies.add :openneo_auth_remember, Openneo::Auth::Strategies::Remember
2010-10-18 14:58:45 -07:00
module Openneo
module Auth
class Config
attr_accessor :app, :auth_server, :secret
2010-11-13 16:42:56 -08:00
def find_user_with_remote_auth(data)
raise "Must set a remote user finder for Openneo Auth to find a user" unless @remote_auth_user_finder
@remote_auth_user_finder.call(data)
2010-10-18 14:58:45 -07:00
end
2010-11-13 16:42:56 -08:00
def find_user_by_remembering(id)
raise "Must set a remember user finder for Openneo Auth to find a user" unless @remember_user_finder
@remember_user_finder.call(id)
end
def remote_auth_user_finder(&block)
@remote_auth_user_finder = block
end
def remember_user_finder(&block)
@remember_user_finder = block
2010-10-18 14:58:45 -07:00
end
end
class << self
def config
@@config ||= Config.new
end
def configure(&block)
block.call(config)
end
def remote_auth_url(params, session)
raise "Must set config.app to this app's subdomain" unless config.app
raise "Must set config.auth_server to remote server's hostname" unless config.auth_server
query = {
:app => config.app,
:session_id => session[:session_id],
2011-01-10 14:52:26 -08:00
:path => params[:return_to] || '/',
:from => params[:from]
2010-10-18 14:58:45 -07:00
}.to_query
uri = URI::HTTP.build({
:host => config.auth_server,
:path => '/',
:query => query
})
uri.to_s
end
2011-01-10 14:52:26 -08:00
def remote_settings_url
URI::HTTP.build({
:host => config.auth_server,
:path => '/users/edit'
}).to_s
end
2010-10-18 14:58:45 -07:00
end
end
end