johnbender (owner)

Revisions

gist: 199207 Download_button fork
public
Public Clone URL: git://gist.github.com/199207.git
Embed All Files: show embed
creds_cont.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class OAuthCredentialsController < ApplicationController
  before_filter :source, :already_authed?
 
  def new
    #build initial request tokens
    request_token, session[:unauthed_token] = @source.request_tokens
 
    #TODO callback should be call_back_path from source id or some such
    redirect_to @source.auth_url(request_token, "http://localhost:3000#{oauth_callback_path(@source.id)}")
  end
 
  def callback
 
    #assuming the authorization has been approved get the information
    access_tokens_hash = @source.access_tokens(:request_token => session[:unauthed_token][:token],
                                              :request_token_secret => session[:unauthed_token][:secret])
    
   
    #store it for later use
    session[:authed_token] = access_tokens_hash
 
    #TODD rescue from invalid or not permissioned, redirect/log
    #TODO save in db as new OAuthCredential with current user and @source.id
    #TODO start initial data pull
    #TODO redirect to some page
  end
 
  private
 
  #TODO should be moved to mixin once other auth types are integrated
  def source
    debugger
    @source = DataSource.find(params[:data_source_id])
  end
 
  def already_authed?
    #TODO redirect somewhere if credentials exist
  end
end