Created
April 5, 2011 17:47
-
-
Save outoftime/904100 to your computer and use it in GitHub Desktop.
Add support for OmniAuth callbacks defined at runtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Including this module in an OmniAuth strategy implementation allows it to have | |
# a runtime-defined callback path extension. The callback path always begins | |
# with the predefined callback path, but may extend it. Specify a callback path | |
# extension at runtime by passing the 'callback' parameter to the request-phase | |
# auth URL. For example, the below URL: | |
# | |
# http://your.host/auth/facebook?callback=users/create | |
# | |
# Will issue a callback to: | |
# | |
# http://your.host/auth/facebook/callback/users/create | |
# | |
# You should thus configure your routes file to send this route to the | |
# appropriate controller/action. | |
# | |
module OmniAuth | |
module RuntimeCallback | |
def call!(env) | |
@env = env | |
if callback_url_prefix =~ request.path | |
callback_phase | |
else | |
super | |
end | |
end | |
def callback_url | |
if callback_url_prefix =~ request.path | |
"#{request.scheme}://#{request.host_with_port}#{request.path}" | |
elsif request.params.has_key?('callback') | |
callback = request.params['callback'] | |
if callback =~ %r(^/) | |
"#{super}#{callback}" | |
else | |
"#{super}/#{callback}" | |
end | |
else | |
super | |
end | |
end | |
private | |
def callback_url_prefix | |
%r(^#{Regexp.escape(OmniAuth.config.path_prefix)}/#{name}/callback/) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module OmniAuth | |
# | |
# Include this module in a strategy to pass request parameters in the request | |
# phase through to the auth request. | |
# | |
module RuntimeOptions | |
def call!(env) | |
@env = env | |
request.params.each_pair do |key, value| | |
options[key.to_sym] = value if key != 'callback' | |
end | |
super | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment