Module: ExvoAuth::Controllers::Base

Defined in:
lib/exvo_auth/controllers/base.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_app_in_scope!(scope) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/exvo_auth/controllers/base.rb', line 39

def authenticate_app_in_scope!(scope)    
  raise("SSL not configured") unless request.ssl? || ExvoAuth::Config.require_ssl == false

  send(basic_authentication_method_name) do |consumer_id, access_token|
    current_scopes = ExvoAuth::Autonomous::Provider.new(
      :consumer_id  => consumer_id,
      :access_token => access_token
    ).scopes

    @current_consumer_id = consumer_id
    
    current_scopes.include?(scope.to_s)
  end
end

#authenticate_user!Object

A before filter to protect your sensitive actions.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/exvo_auth/controllers/base.rb', line 3

def authenticate_user!
  if !signed_in?
    store_request!

    callback_key   = ExvoAuth::Config.callback_key
    callback_value = params[callback_key]

    if callback_value
      redirect_to (callback_key => callback_value)
    else
      redirect_to 
    end
  end
end

#current_consumer_idObject



67
68
69
# File 'lib/exvo_auth/controllers/base.rb', line 67

def current_consumer_id
  @current_consumer_id
end

#current_userObject



62
63
64
65
# File 'lib/exvo_auth/controllers/base.rb', line 62

def current_user
  return @current_user if defined?(@current_user)
  @current_user = session[:user_id] && find_user_by_id(session[:user_id])
end

#sign_in_and_redirect!(user_id) ⇒ Object

Usually this method is called from your sessions#create.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/exvo_auth/controllers/base.rb', line 19

def (user_id)
  session[:user_id] = user_id

  url = if params[:state] == "popup"
    ExvoAuth::Config.host + "/close_popup.html"
  else
    request_replay_url || "/"
  end

  redirect_to url
end

#sign_in_pathObject



54
55
56
# File 'lib/exvo_auth/controllers/base.rb', line 54

def 
  "/auth/interactive"
end

#sign_out_and_redirect!(return_to = "/") ⇒ Object

Redirect to sign_out_url, signs out and redirects back to “/” (by default). Usuallly this method is called from your sessions#destroy.



33
34
35
36
37
# File 'lib/exvo_auth/controllers/base.rb', line 33

def sign_out_and_redirect!(return_to = "/")
  session.delete(:user_id)
  @current_user = nil
  redirect_to sign_out_url(return_to)
end

#sign_up_pathObject



58
59
60
# File 'lib/exvo_auth/controllers/base.rb', line 58

def 
  "/auth/interactive?x_sign_up=true"
end

#signed_in?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/exvo_auth/controllers/base.rb', line 71

def signed_in?
  !!current_user
end