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

Improve "Access Denied" message by distinguishing "no key" vs "unknown key" #4663

Open
duckinator opened this issue Apr 29, 2024 · 0 comments
Labels

Comments

@duckinator
Copy link
Member

Right now, this message seems to be returned by the API for no key being specified and providing a key the server doesn't know about:

Access Denied. Please sign up for an account at https://rubygems.org

If a key is specified, but invalid, it would be nice for it to return a message suggesting gem signin.

(Split from rubygems/rubygems#7595.)

Steps to Reproduce

  1. Sign in via gem signin.
  2. Revoke the key that was generated in step 1.
  3. Try gem push.

Expected Behavior

I'd expect to suggest signing in.

Current Behavior

It currently suggests to signing up.

Possible Solution

Returning the current message if no key is provided, but something closer to this if the key is invalid:

Access Denied. Your key is invalid. Check your keys at https://rubygems.org/profile/api_keys or sign in with gem signin

Environment

Browser and its version: N/A (API behavior)
RubyGems version: definitely 3.3.15, I suspect any recent version

Additional Context

The exact string is defined at https://github.com/rubygems/rubygems.org/blob/14d5bba/config/locales/en.yml#L30.

The function that returns this value is Api::BaseController#authenticate_with_api_key:

def authenticate_with_api_key
params_key = request.headers["Authorization"] || ""
hashed_key = Digest::SHA256.hexdigest(params_key)
@api_key = ApiKey.unexpired.find_by_hashed_key(hashed_key)
return render_unauthorized unless @api_key
set_tags "gemcutter.api_key.owner" => @api_key.owner.to_gid, "gemcutter.user.api_key_id" => @api_key.id
Current.user = @api_key.user
render_soft_deleted_api_key if @api_key.soft_deleted?
end

I suspect but have not confirmed that you may be able to determine which situation it is based on if request.headers["Authorization"] is nil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant