Class: LobbyBoy::OmniAuth::FailureEndpoint

Inherits:
Object
  • Object
show all
Includes:
Functions
Defined in:
lib/lobby_boy/omni_auth/failure_endpoint.rb

Overview

This is a copy of the default OmniAuth FailureEndpoint minus the raise_out! we don’t want and plus the actual error message as opposed to always just ‘missing_code’.

Also when authentication with prompt=none fails it will retry with prompt=login.

Defined Under Namespace

Modules: Functions

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Functions

escape, redirect_to

Constructor Details

#initialize(env) ⇒ FailureEndpoint

Returns a new instance of FailureEndpoint.



15
16
17
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 15

def initialize(env)
  @env = env
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



9
10
11
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 9

def env
  @env
end

Class Method Details

.call(env) ⇒ Object



11
12
13
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 11

def self.call(env)
  new(env).call
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 19

def call
  if script?
    redirect_to '/session/state?state=unauthenticated'
  elsif retry?
    retry_interactive
  else
    redirect_to_failure
  end
end

#errorObject



37
38
39
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 37

def error
  env['omniauth.error'] || ::OmniAuth::Error.new(env['omniauth.error.type'])
end

#message_query_param(message) ⇒ Object



81
82
83
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 81

def message_query_param(message)
  'message=' + escape(message)
end

#omniauth_pathObject



73
74
75
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 73

def omniauth_path
  script_name + ::OmniAuth.config.path_prefix
end

#originObject



93
94
95
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 93

def origin
  env['omniauth.origin']
end

#origin_query_paramObject



97
98
99
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 97

def origin_query_param
  'origin=' + escape(origin) if origin
end

#paramsObject



29
30
31
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 29

def params
  request.params
end

#redirect_to_failureObject



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 61

def redirect_to_failure
  params = [
    message_query_param(error.message),
    origin_query_param,
    strategy_name_query_param
  ]

  url = omniauth_path + '/failure?' + params.compact.join('&')

  redirect_to url
end

#requestObject



33
34
35
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 33

def request
  @request ||= ::Rack::Request.new env
end

#retry?Boolean

Authentication with &prompt=none fails if the user is not already signed in with the respective provider. Retry without &prompt=none in that case.

Google responds with ‘immediate_failed’ in that case. Our own concierge with ‘interaction_required’.

Returns:

  • (Boolean)


51
52
53
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 51

def retry?
  ['immediate_failed', 'interaction_required'].include? error.message
end

#retry_interactiveObject



55
56
57
58
59
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 55

def retry_interactive
  url = "#{omniauth_path}/#{strategy.name}?#{origin_query_param}&prompt=login"

  redirect_to url
end

#script?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 41

def script?
  origin =~ /#{script_name}\/session\/state/
end

#script_nameObject



77
78
79
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 77

def script_name
  env['SCRIPT_NAME']
end

#strategyObject



89
90
91
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 89

def strategy
  env['omniauth.error.strategy']
end

#strategy_name_query_paramObject



85
86
87
# File 'lib/lobby_boy/omni_auth/failure_endpoint.rb', line 85

def strategy_name_query_param
  'strategy=' + escape(strategy.name) if strategy
end