提交 b8bc80c5 编写于 作者: M Mislav Marohnić

Include the current machine identifier when creating Access Tokens

Previously, the description for the token was simply "hub". Now, it's:

    hub for {USER}@{HOSTNAME}

This reduces the chance of token name collisions when the same user uses
hub to authenticate from different machines, as well as serves as
information to distinguish between various tokens in user's Personal
Acess Token list.
上级 55b58054
...@@ -5,10 +5,14 @@ Feature: OAuth authentication ...@@ -5,10 +5,14 @@ Feature: OAuth authentication
Scenario: Ask for username & password, create authorization Scenario: Ask for username & password, create authorization
Given the GitHub API server: Given the GitHub API server:
""" """
require 'socket'
require 'etc'
machine_id = "#{Etc.getlogin}@#{Socket.gethostname}"
post('/authorizations') { post('/authorizations') {
assert_basic_auth 'mislav', 'kitty' assert_basic_auth 'mislav', 'kitty'
assert :scopes => ['repo'], assert :scopes => ['repo'],
:note => 'hub', :note => "hub for #{machine_id}",
:note_url => 'http://hub.github.com/' :note_url => 'http://hub.github.com/'
json :token => 'OTOKEN' json :token => 'OTOKEN'
} }
......
...@@ -337,7 +337,7 @@ module Hub ...@@ -337,7 +337,7 @@ module Hub
auth_url = URI.parse("https://%s@%s/authorizations" % [CGI.escape(user), host]) auth_url = URI.parse("https://%s@%s/authorizations" % [CGI.escape(user), host])
auth_params = { auth_params = {
:scopes => ['repo'], :scopes => ['repo'],
:note => 'hub', :note => "hub for #{local_user}@#{local_hostname}",
:note_url => oauth_app_url :note_url => oauth_app_url
} }
res = nil res = nil
...@@ -359,6 +359,16 @@ module Hub ...@@ -359,6 +359,16 @@ module Hub
res.data['token'] res.data['token']
end end
def local_user
require 'etc'
Etc.getlogin
end
def local_hostname
require 'socket'
Socket.gethostname
end
end end
module GistAuth module GistAuth
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册