Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
102e0e6d
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
102e0e6d
编写于
10月 23, 2020
作者:
R
Rachel Macfarlane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Handle incomplete login requests gracefully, fixes #109102
上级
0124f688
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
82 addition
and
34 deletion
+82
-34
extensions/github-authentication/src/githubServer.ts
extensions/github-authentication/src/githubServer.ts
+49
-30
extensions/microsoft-authentication/src/AADHelper.ts
extensions/microsoft-authentication/src/AADHelper.ts
+33
-4
未找到文件。
extensions/github-authentication/src/githubServer.ts
浏览文件 @
102e0e6d
...
...
@@ -25,36 +25,7 @@ export const uriHandler = new UriEventHandler;
const
onDidManuallyProvideToken
=
new
vscode
.
EventEmitter
<
string
>
();
const
exchangeCodeForToken
:
(
state
:
string
)
=>
PromiseAdapter
<
vscode
.
Uri
,
string
>
=
(
state
)
=>
async
(
uri
,
resolve
,
reject
)
=>
{
Logger
.
info
(
'
Exchanging code for token...
'
);
const
query
=
parseQuery
(
uri
);
const
code
=
query
.
code
;
if
(
query
.
state
!==
state
)
{
reject
(
'
Received mismatched state
'
);
return
;
}
try
{
const
result
=
await
fetch
(
`https://
${
AUTH_RELAY_SERVER
}
/token?code=
${
code
}
&state=
${
state
}
`
,
{
method
:
'
POST
'
,
headers
:
{
Accept
:
'
application/json
'
}
});
if
(
result
.
ok
)
{
const
json
=
await
result
.
json
();
Logger
.
info
(
'
Token exchange success!
'
);
resolve
(
json
.
access_token
);
}
else
{
reject
(
result
.
statusText
);
}
}
catch
(
ex
)
{
reject
(
ex
);
}
};
function
parseQuery
(
uri
:
vscode
.
Uri
)
{
return
uri
.
query
.
split
(
'
&
'
).
reduce
((
prev
:
any
,
current
)
=>
{
...
...
@@ -67,6 +38,9 @@ function parseQuery(uri: vscode.Uri) {
export
class
GitHubServer
{
private
_statusBarItem
:
vscode
.
StatusBarItem
|
undefined
;
private
_pendingStates
=
new
Map
<
string
,
string
[]
>
();
private
_codeExchangePromises
=
new
Map
<
string
,
Promise
<
string
>>
();
private
isTestEnvironment
(
url
:
vscode
.
Uri
):
boolean
{
return
url
.
authority
===
'
vscode-web-test-playground.azurewebsites.net
'
||
url
.
authority
.
startsWith
(
'
localhost:
'
);
}
...
...
@@ -91,18 +65,63 @@ export class GitHubServer {
this
.
updateStatusBarItem
(
false
);
return
token
;
}
else
{
const
existingStates
=
this
.
_pendingStates
.
get
(
scopes
)
||
[];
this
.
_pendingStates
.
set
(
scopes
,
[...
existingStates
,
state
]);
const
uri
=
vscode
.
Uri
.
parse
(
`https://
${
AUTH_RELAY_SERVER
}
/authorize/?callbackUri=
${
encodeURIComponent
(
callbackUri
.
toString
())}
&scope=
${
scopes
}
&state=
${
state
}
&responseType=code&authServer=https://github.com`
);
await
vscode
.
env
.
openExternal
(
uri
);
}
// Register a single listener for the URI callback, in case the user starts the login process multiple times
// before completing it.
let
existingPromise
=
this
.
_codeExchangePromises
.
get
(
scopes
);
if
(
!
existingPromise
)
{
existingPromise
=
promiseFromEvent
(
uriHandler
.
event
,
this
.
exchangeCodeForToken
(
scopes
));
this
.
_codeExchangePromises
.
set
(
scopes
,
existingPromise
);
}
return
Promise
.
race
([
promiseFromEvent
(
uriHandler
.
event
,
exchangeCodeForToken
(
state
))
,
existingPromise
,
promiseFromEvent
<
string
,
string
>
(
onDidManuallyProvideToken
.
event
)
]).
finally
(()
=>
{
this
.
_pendingStates
.
delete
(
scopes
);
this
.
_codeExchangePromises
.
delete
(
scopes
);
this
.
updateStatusBarItem
(
false
);
});
}
private
exchangeCodeForToken
:
(
scopes
:
string
)
=>
PromiseAdapter
<
vscode
.
Uri
,
string
>
=
(
scopes
)
=>
async
(
uri
,
resolve
,
reject
)
=>
{
Logger
.
info
(
'
Exchanging code for token...
'
);
const
query
=
parseQuery
(
uri
);
const
code
=
query
.
code
;
const
acceptedStates
=
this
.
_pendingStates
.
get
(
scopes
)
||
[];
if
(
!
acceptedStates
.
includes
(
query
.
state
))
{
reject
(
'
Received mismatched state
'
);
return
;
}
try
{
const
result
=
await
fetch
(
`https://
${
AUTH_RELAY_SERVER
}
/token?code=
${
code
}
&state=
${
query
.
state
}
`
,
{
method
:
'
POST
'
,
headers
:
{
Accept
:
'
application/json
'
}
});
if
(
result
.
ok
)
{
const
json
=
await
result
.
json
();
Logger
.
info
(
'
Token exchange success!
'
);
resolve
(
json
.
access_token
);
}
else
{
reject
(
result
.
statusText
);
}
}
catch
(
ex
)
{
reject
(
ex
);
}
};
private
updateStatusBarItem
(
isStart
?:
boolean
)
{
if
(
isStart
&&
!
this
.
_statusBarItem
)
{
this
.
_statusBarItem
=
vscode
.
window
.
createStatusBarItem
(
vscode
.
StatusBarAlignment
.
Left
);
...
...
extensions/microsoft-authentication/src/AADHelper.ts
浏览文件 @
102e0e6d
...
...
@@ -95,6 +95,11 @@ export class AzureActiveDirectoryService {
private
_uriHandler
:
UriEventHandler
;
private
_disposables
:
vscode
.
Disposable
[]
=
[];
// Used to keep track of current requests when not using the local server approach.
private
_pendingStates
=
new
Map
<
string
,
string
[]
>
();
private
_codeExchangePromises
=
new
Map
<
string
,
Promise
<
vscode
.
AuthenticationSession
>>
();
private
_codeVerfifiers
=
new
Map
<
string
,
string
>
();
constructor
()
{
this
.
_uriHandler
=
new
UriEventHandler
();
this
.
_disposables
.
push
(
vscode
.
window
.
registerUriHandler
(
this
.
_uriHandler
));
...
...
@@ -385,10 +390,28 @@ export class AzureActiveDirectoryService {
},
1000
*
60
*
5
);
});
return
Promise
.
race
([
this
.
handleCodeResponse
(
state
,
codeVerifier
,
scope
),
timeoutPromise
]);
const
existingStates
=
this
.
_pendingStates
.
get
(
scope
)
||
[];
this
.
_pendingStates
.
set
(
scope
,
[...
existingStates
,
state
]);
// Register a single listener for the URI callback, in case the user starts the login process multiple times
// before completing it.
let
existingPromise
=
this
.
_codeExchangePromises
.
get
(
scope
);
if
(
!
existingPromise
)
{
existingPromise
=
this
.
handleCodeResponse
(
scope
);
this
.
_codeExchangePromises
.
set
(
scope
,
existingPromise
);
}
this
.
_codeVerfifiers
.
set
(
state
,
codeVerifier
);
return
Promise
.
race
([
existingPromise
,
timeoutPromise
])
.
finally
(()
=>
{
this
.
_pendingStates
.
delete
(
scope
);
this
.
_codeExchangePromises
.
delete
(
scope
);
this
.
_codeVerfifiers
.
delete
(
state
);
});
}
private
async
handleCodeResponse
(
s
tate
:
string
,
codeVerifier
:
string
,
s
cope
:
string
):
Promise
<
vscode
.
AuthenticationSession
>
{
private
async
handleCodeResponse
(
scope
:
string
):
Promise
<
vscode
.
AuthenticationSession
>
{
let
uriEventListener
:
vscode
.
Disposable
;
return
new
Promise
((
resolve
:
(
value
:
vscode
.
AuthenticationSession
)
=>
void
,
reject
)
=>
{
uriEventListener
=
this
.
_uriHandler
.
event
(
async
(
uri
:
vscode
.
Uri
)
=>
{
...
...
@@ -396,12 +419,18 @@ export class AzureActiveDirectoryService {
const
query
=
parseQuery
(
uri
);
const
code
=
query
.
code
;
const
acceptedStates
=
this
.
_pendingStates
.
get
(
scope
)
||
[];
// Workaround double encoding issues of state in web
if
(
query
.
state
!==
state
&&
decodeURIComponent
(
query
.
state
)
!==
state
)
{
if
(
!
acceptedStates
.
includes
(
query
.
state
)
&&
!
acceptedStates
.
includes
(
decodeURIComponent
(
query
.
state
))
)
{
throw
new
Error
(
'
State does not match.
'
);
}
const
token
=
await
this
.
exchangeCodeForToken
(
code
,
codeVerifier
,
scope
);
const
verifier
=
this
.
_codeVerfifiers
.
get
(
query
.
state
)
??
this
.
_codeVerfifiers
.
get
(
decodeURIComponent
(
query
.
state
));
if
(
!
verifier
)
{
throw
new
Error
(
'
No available code verifier
'
);
}
const
token
=
await
this
.
exchangeCodeForToken
(
code
,
verifier
,
scope
);
this
.
setToken
(
token
,
scope
);
const
session
=
await
this
.
convertToSession
(
token
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录