Created
November 24, 2010 02:57
-
-
Save gamesthatgive/713018 to your computer and use it in GitHub Desktop.
This file contains 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
# 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