Skip to content

Instantly share code, notes, and snippets.

@gamesthatgive
Created November 24, 2010 02:57
Show Gist options
  • Save gamesthatgive/713018 to your computer and use it in GitHub Desktop.
Save gamesthatgive/713018 to your computer and use it in GitHub Desktop.
# in routes.rb
match '/oauth/create' => 'oauth#create', :as => 'oauth_callback'
resource :oauth, :only => :new, :controller => 'oauth'
# controller
class OauthController < ApplicationController
def new
session[:token] = nil
flash[:next] = params[:next]
top_redirect_to authenticator.authorize_url(:scope => params[:scope], :display => :page)
end
def create
# oauth callback is invoked if denied as well, so make sure we have a code
if params[:code]
client = Mogli::Client.create_from_code_and_authenticator(params[:code], authenticator)
session[:token] = client.access_token
end
top_redirect_to flash[:next]
end
private
def authenticator
@authenticator ||= Mogli::Authenticator.new(current_account.app_id,
current_account.api_secret,
oauth_callback_url(:host => current_account_canvas))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment