Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

persist correctly capitalized login name for the user

Fixes #263
  • Loading branch information...
commit bc361d0c5a5cc0b5702fdf729c49ddbf05d4e943 1 parent f505f01
@mislav mislav authored
Showing with 28 additions and 1 deletion.
  1. +12 −0 features/authentication.feature
  2. +16 −1 lib/hub/github_api.rb
View
12 features/authentication.feature
@@ -13,7 +13,12 @@ Feature: OAuth authentication
halt 400 unless params[:scopes] == ['repo']
json :token => 'OTOKEN'
}
+ get('/user') {
+ halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN'
+ json :login => 'MiSlAv'
+ }
post('/user/repos') {
+ halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN'
json :full_name => 'mislav/dotfiles'
}
"""
@@ -23,6 +28,7 @@ Feature: OAuth authentication
Then the output should contain "github.com username:"
And the output should contain "github.com password for mislav (never stored):"
And the exit status should be 0
+ And the file "../home/.config/hub" should contain "user: MiSlAv"
And the file "../home/.config/hub" should contain "oauth_token: OTOKEN"
And the file "../home/.config/hub" should have mode "0600"
@@ -38,6 +44,9 @@ Feature: OAuth authentication
{:token => 'OTOKEN', :app => {:url => 'http://defunkt.io/hub/'}}
]
}
+ get('/user') {
+ json :login => 'mislav'
+ }
post('/user/repos') {
json :full_name => 'mislav/dotfiles'
}
@@ -60,6 +69,9 @@ Feature: OAuth authentication
{:token => 'OTOKEN', :app => {:url => 'http://defunkt.io/hub/'}}
]
}
+ get('/user') {
+ json :login => 'mislav'
+ }
post('/user/repos') {
json :full_name => 'mislav/dotfiles'
}
View
17 lib/hub/github_api.rb
@@ -66,7 +66,7 @@ def fork_repo project
# Public: Create a new project.
def create_repo project, options = {}
- is_org = project.owner != config.username(api_host(project.host))
+ is_org = project.owner.downcase != config.username(api_host(project.host)).downcase
params = { :name => project.name, :private => !!options[:private] }
params[:description] = options[:description] if options[:description]
params[:homepage] = options[:homepage] if options[:homepage]
@@ -115,6 +115,7 @@ def create_pullrequest options
# Requires access to a `config` object that implements:
# - proxy_uri(with_ssl)
# - username(host)
+ # - update_username(host, old_username, new_username)
# - password(host, user)
module HttpMethods
# Decorator for Net::HTTPResponse
@@ -234,10 +235,18 @@ def apply_authentication req, url
if (req.path =~ /\/authorizations$/)
super
else
+ refresh = false
user = url.user || config.username(url.host)
token = config.oauth_token(url.host, user) {
+ refresh = true
obtain_oauth_token url.host, user
}
+ if refresh
+ # get current user info user to persist correctly capitalized login name
+ res = get "https://#{url.host}/user"
+ res.error! unless res.success?
+ config.update_username(url.host, user, res.data['login'])
+ end
req['Authorization'] = "token #{token}"
end
end
@@ -339,6 +348,12 @@ def username host
end
end
+ def update_username host, old_username, new_username
+ entry = @data.entry_for_user(normalize_host(host), old_username)
+ entry['user'] = new_username
+ @data.save
+ end
+
def api_token host, user
host = normalize_host host
@data.fetch_value host, user, :api_token do
Please sign in to comment.
Something went wrong with that request. Please try again.