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.

Revisions

  1. gamesthatgive revised this gist Nov 24, 2010. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,8 @@
    # 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
    @@ -21,4 +26,4 @@ class OauthController < ApplicationController
    current_account.api_secret,
    oauth_callback_url(:host => current_account_canvas))
    end
    end
    end
  2. gamesthatgive created this gist Nov 24, 2010.
    24 changes: 24 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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