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



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

def authenticate_app_in_scope!(scope)
  raise("SSL not configured. Your api needs to be exposed using https protocol.") unless request.ssl? || ExvoAuth::Config.require_ssl == false

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

    @current_app_id = app_id

    current_scopes.include?(scope.to_s)
  end
end

#authenticate_user!(opts = {}) ⇒ 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!(opts = {})
  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 opts[:redirect_to] || 
    end
  end
end

#current_app_idObject



69
70
71
# File 'lib/exvo_auth/controllers/base.rb', line 69

def current_app_id
  @current_app_id
end

#current_userObject



64
65
66
67
# File 'lib/exvo_auth/controllers/base.rb', line 64

def current_user
  return @current_user unless @current_user.nil?
  @current_user = session[:user_uid] && find_or_create_user_by_uid(session[:user_uid])
end

#sign_in_and_redirect!Object

Usually this method is called from your sessions#create.



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

def 
  session[:user_uid] = request.env["omniauth.auth"]["uid"]

  url = if params[:state] == "popup"
    ExvoAuth::Config.uri + "/close_popup.html"
  elsif params[:state] # if not popup then an url
    params[:state]
  else
    request_replay_url || "/"
  end

  redirect_to url
end

#sign_in_pathObject



56
57
58
# File 'lib/exvo_auth/controllers/base.rb', line 56

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.



35
36
37
38
39
# File 'lib/exvo_auth/controllers/base.rb', line 35

def sign_out_and_redirect!(return_to = "/")
  session.clear
  remove_instance_variable(:@current_user) if instance_variable_defined?(:@current_user)
  redirect_to sign_out_url(return_to)
end

#sign_up_pathObject



60
61
62
# File 'lib/exvo_auth/controllers/base.rb', line 60

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

#signed_in?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/exvo_auth/controllers/base.rb', line 73

def signed_in?
  !!current_user
end