Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #36889 - Add error message to indicate failed authentication #9890

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/controllers/api/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ def authorize

unless authenticate
count_login_failure
render_error('unauthorized', :status => :unauthorized, :locals => { :user_login => @available_sso.try(:user) })
message = @available_sso.try(:failed_auth_message)
render_error('unauthorized', status: :unauthorized, locals: { user_login: @available_sso.try(:user), message: message ? _(message) : ''})
return false
end

Expand Down
7 changes: 5 additions & 2 deletions app/services/sso/jwt.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module SSO
class Jwt < Base
attr_reader :current_user
attr_reader :failed_auth_message

def available?
controller.api_request? && bearer_token_set? && no_issuer?
Expand All @@ -19,10 +20,12 @@ def authenticate!
@current_user = user
user&.login
rescue JWT::ExpiredSignature
Rails.logger.warn "JWT SSO: Expired JWT token."
@failed_auth_message = N_("JWT SSO: Expired JWT token.")
Rails.logger.warn @failed_auth_message
nil
rescue JWT::DecodeError
Rails.logger.warn "JWT SSO: Failed to decode JWT."
@failed_auth_message = N_("JWT SSO: Failed to decode JWT.")
Rails.logger.warn @failed_auth_message
nil
end

Expand Down