Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Gem::GemcutterUtilities#sign_in
sign_in(sign_in_host = nil, scope: nil)
lib/rubygems/gemcutter_utilities.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/rubygems/gemcutter_utilities.rb, line 168
def sign_in(sign_in_host = nil, scope: nil)
sign_in_host ||= host
pretty_host = pretty_host(sign_in_host)
# Stopping because the store cannot be read would close the one command
# that can re-authenticate. A flag rather than an argument keeps #api_key
# callable with no arguments, as command plugins that override it define it.
@recognizing_session = true
signed_in = begin
api_key
ensure
@recognizing_session = false
end
if signed_in
say "You are already signed in on #{pretty_host}."
return
end
say "Enter your #{pretty_host} credentials."
say "Don't have an account yet? " \
"Create one at #{sign_in_host}/sign_up"
identifier = ask "Username/email: "
password = ask_for_password " Password: "
say "\n"
key_name = get_key_name(scope)
scope_params = get_scope_params(scope)
profile = get_user_profile(identifier, password)
mfa_params = get_mfa_params(profile)
all_params = scope_params.merge(mfa_params)
warning = profile["warning"]
credentials = { identifier: identifier, password: password }
say "#{warning}\n" if warning
response = rubygems_api_request(:post, "api/v1/api_key",
sign_in_host, credentials: credentials, scope: scope) do |request|
request.basic_auth identifier, password
request.body = Gem::URI.encode_www_form({ name: key_name }.merge(all_params))
end
with_response response do |resp|
say "Signed in with API key: #{key_name}."
set_api_key host, resp.body
end
end
Signs in with the RubyGems API at sign_in_host and sets the rubygems API key.
See also
#set_api_key
#stored_api_key_named
#rubygems_api_request
#update_scope
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0