Class: LcpRuby::Auth::CallbacksController
Overview
Receives the OIDC callback from OmniAuth, hands the auth_hash to UserResolver, and signs the user in via Warden. Routes are drawn in config/routes.rb behind ProviderRegistry.oidc_enabled?.
Constant Summary
collapse
- ALLOWED_FAILURE_REASONS =
%w[
invalid_credentials access_denied no_role_match host_rejected unknown_provider generic
].freeze
- EXCEPTION_TO_REASON =
{
LcpRuby::Authentication::UnknownProvider => "unknown_provider",
LcpRuby::Authentication::NoRoleMatch => "no_role_match",
LcpRuby::Authentication::HostRejected => "host_rejected",
LcpRuby::Authentication::InvalidClaims => "invalid_credentials"
}.freeze
Controller::BearerAuthentication::BASIC_PREFIX_LENGTH, Controller::BearerAuthentication::BEARER_PREFIX_LENGTH
Instance Method Summary
collapse
#current_evaluator
Instance Method Details
#callback ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'app/controllers/lcp_ruby/auth/callbacks_controller.rb', line 37
def callback
provider = LcpRuby::Authentication::ProviderRegistry.find(params[:provider])
auth = omniauth_auth
unless auth
Rails.logger.warn(
"[lcp_ruby] OIDC callback missing omniauth.auth provider=#{params[:provider]} " \
"request_id=#{request.request_id}"
)
redirect_to lcp_ruby.oidc_failure_path(reason: "invalid_credentials") and return
end
user = LcpRuby::Authentication::UserResolver.call(auth: auth, provider: provider)
return_to = safe_return_to(stored_location_for(:user))
id_token = if provider.logout[:mode] == :rp_initiated
auth.respond_to?(:credentials) && auth.credentials.respond_to?(:id_token) ?
auth.credentials.id_token : nil
end
reset_session
session[:oidc_id_token] = id_token if id_token
sign_in(user, event: :authentication)
redirect_to signed_in_redirect_path(return_to)
rescue *EXCEPTION_TO_REASON.keys => e
if e.is_a?(LcpRuby::Authentication::InvalidClaims)
Rails.logger.warn(
"[lcp_ruby] OIDC invalid_claims provider=#{params[:provider]} " \
"request_id=#{request.request_id}: #{e.message}"
)
end
redirect_to lcp_ruby.oidc_failure_path(reason: EXCEPTION_TO_REASON.fetch(e.class))
end
|
#failure ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'app/controllers/lcp_ruby/auth/callbacks_controller.rb', line 80
def failure
candidates = [ params[:reason].to_s, request.env["omniauth.error.type"]&.to_s ]
@reason = candidates.find { |r| ALLOWED_FAILURE_REASONS.include?(r) } || "generic"
@exception = request.env["omniauth.error"]
@request_id = request.request_id
provider_log = params[:provider] || request.env["omniauth.error.strategy"]&.name
Rails.logger.warn(
"[lcp_ruby] OIDC failure reason=#{@reason} provider=#{provider_log} " \
"request_id=#{@request_id} exception=#{@exception&.class&.name}"
)
render "lcp_ruby/auth/callbacks/failure"
end
|
#passthru ⇒ Object
30
31
32
33
34
35
|
# File 'app/controllers/lcp_ruby/auth/callbacks_controller.rb', line 30
def passthru
render plain: I18n.t("lcp_ruby.auth.failure.generic", default: "Not found"), status: :not_found
end
|