Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
865b3f34
H
hub
项目概览
github
/
hub
10 个月 前同步成功
通知
3
Star
22523
Fork
2406
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
865b3f34
编写于
5月 18, 2018
作者:
M
Mislav Marohnić
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'llimllib-token-instead-of-password'
Closes #1740
上级
1e5bb959
5f9b034b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
1 deletion
+66
-1
features/authentication.feature
features/authentication.feature
+48
-0
github/client.go
github/client.go
+18
-1
未找到文件。
features/authentication.feature
浏览文件 @
865b3f34
...
...
@@ -37,6 +37,54 @@ Feature: OAuth authentication
And the file "../home/.config/hub" should contain "oauth_token
:
OTOKEN"
And
the file
"../home/.config/hub"
should have mode
"0600"
Scenario
:
Prompt for username & password, receive personal access token
Given the GitHub API server
:
"""
get('/user') {
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token 0123456789012345678901234567890123456789'
json :login => 'llIMLLib'
}
post('/user/repos') {
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token 0123456789012345678901234567890123456789'
status 201
json :full_name => 'llimllib/dotfiles'
}
"""
When
I run `hub create` interactively
When
I type
"llimllib"
And
I type
"0123456789012345678901234567890123456789"
And
the exit status should be 0
And the file "../home/.config/hub" should contain "user
:
llIMLLib"
And the file "../home/.config/hub" should contain
:
"""
oauth_token: "0123456789012345678901234567890123456789"
"""
Scenario
:
Ask for username & password, receive password that looks like a token
Given the GitHub API server
:
"""
post('/authorizations') {
assert_basic_auth 'llimllib', '0123456789012345678901234567890123456789'
status 201
json :token => 'OTOKEN'
}
get('/user') {
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN'
json :login => 'llIMLLib'
}
post('/user/repos') {
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN'
status 201
json :full_name => 'llimllib/dotfiles'
}
"""
When
I run `hub create` interactively
When
I type
"llimllib"
And
I type
"0123456789012345678901234567890123456789"
And
the exit status should be 0
And the file "../home/.config/hub" should contain "user
:
llIMLLib"
And the file "../home/.config/hub" should contain "oauth_token
:
OTOKEN"
Scenario
:
Rename & retry creating authorization if there's a token name collision
Given the GitHub API server
:
"""
...
...
github/client.go
浏览文件 @
865b3f34
...
...
@@ -683,13 +683,30 @@ type AuthorizationEntry struct {
Token
string
`json:"token"`
}
func
isToken
(
api
*
simpleClient
,
password
string
)
bool
{
api
.
PrepareRequest
=
func
(
req
*
http
.
Request
)
{
req
.
Header
.
Set
(
"Authorization"
,
"token "
+
password
)
}
res
,
_
:=
api
.
Get
(
"user"
)
if
res
!=
nil
&&
res
.
StatusCode
==
200
{
return
true
}
return
false
}
func
(
client
*
Client
)
FindOrCreateToken
(
user
,
password
,
twoFactorCode
string
)
(
token
string
,
err
error
)
{
api
:=
client
.
apiClient
()
if
len
(
password
)
>=
40
&&
isToken
(
api
,
password
)
{
return
password
,
nil
}
params
:=
map
[
string
]
interface
{}{
"scopes"
:
[]
string
{
"repo"
},
"note_url"
:
OAuthAppURL
,
}
api
:=
client
.
apiClient
()
api
.
PrepareRequest
=
func
(
req
*
http
.
Request
)
{
req
.
SetBasicAuth
(
user
,
password
)
if
twoFactorCode
!=
""
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录