Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
c8529766
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c8529766
编写于
1月 11, 2021
作者:
R
Rachel Macfarlane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move id, label, and options to authentication provider registration
上级
e9ae0082
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
65 addition
and
80 deletion
+65
-80
extensions/github-authentication/src/extension.ts
extensions/github-authentication/src/extension.ts
+2
-5
extensions/microsoft-authentication/src/extension.ts
extensions/microsoft-authentication/src/extension.ts
+2
-5
src/vs/vscode.proposed.d.ts
src/vs/vscode.proposed.d.ts
+17
-22
src/vs/workbench/api/common/extHost.api.impl.ts
src/vs/workbench/api/common/extHost.api.impl.ts
+2
-2
src/vs/workbench/api/common/extHostAuthentication.ts
src/vs/workbench/api/common/extHostAuthentication.ts
+42
-46
未找到文件。
extensions/github-authentication/src/extension.ts
浏览文件 @
c8529766
...
...
@@ -22,10 +22,7 @@ export async function activate(context: vscode.ExtensionContext) {
return
loginService
.
manuallyProvideToken
();
}));
context
.
subscriptions
.
push
(
vscode
.
authentication
.
registerAuthenticationProvider
({
id
:
'
github
'
,
label
:
'
GitHub
'
,
supportsMultipleAccounts
:
false
,
context
.
subscriptions
.
push
(
vscode
.
authentication
.
registerAuthenticationProvider
(
'
github
'
,
'
GitHub
'
,
{
onDidChangeSessions
:
onDidChangeSessions
.
event
,
getSessions
:
()
=>
Promise
.
resolve
(
loginService
.
sessions
),
login
:
async
(
scopeList
:
string
[])
=>
{
...
...
@@ -79,7 +76,7 @@ export async function activate(context: vscode.ExtensionContext) {
throw
e
;
}
}
}));
}
,
{
supportsMultipleAccounts
:
false
}
));
return
;
}
...
...
extensions/microsoft-authentication/src/extension.ts
浏览文件 @
c8529766
...
...
@@ -18,10 +18,7 @@ export async function activate(context: vscode.ExtensionContext) {
await
loginService
.
initialize
();
context
.
subscriptions
.
push
(
vscode
.
authentication
.
registerAuthenticationProvider
({
id
:
'
microsoft
'
,
label
:
'
Microsoft
'
,
supportsMultipleAccounts
:
true
,
context
.
subscriptions
.
push
(
vscode
.
authentication
.
registerAuthenticationProvider
(
'
microsoft
'
,
'
Microsoft
'
,
{
onDidChangeSessions
:
onDidChangeSessions
.
event
,
getSessions
:
()
=>
Promise
.
resolve
(
loginService
.
sessions
),
login
:
async
(
scopes
:
string
[])
=>
{
...
...
@@ -59,7 +56,7 @@ export async function activate(context: vscode.ExtensionContext) {
telemetryReporter
.
sendTelemetryEvent
(
'
logoutFailed
'
);
}
}
}));
}
,
{
supportsMultipleAccounts
:
true
}
));
return
;
}
...
...
src/vs/vscode.proposed.d.ts
浏览文件 @
c8529766
...
...
@@ -73,28 +73,9 @@ declare module 'vscode' {
}
/**
* **WARNING** When writing an AuthenticationProvider, `id` should be treated as part of your extension's
* API, changing it is a breaking change for all extensions relying on the provider. The id is
* treated case-sensitively.
* A provider for performing authentication to a service.
*/
export
interface
AuthenticationProvider
{
/**
* Used as an identifier for extensions trying to work with a particular
* provider: 'microsoft', 'github', etc. id must be unique, registering
* another provider with the same id will fail.
*/
readonly
id
:
string
;
/**
* The human-readable name of the provider.
*/
readonly
label
:
string
;
/**
* Whether it is possible to be signed into multiple accounts at once with this provider
*/
readonly
supportsMultipleAccounts
:
boolean
;
/**
* An [event](#Event) which fires when the array of sessions has changed, or data
* within a session has changed.
...
...
@@ -121,17 +102,31 @@ declare module 'vscode' {
logout
(
sessionId
:
string
):
Thenable
<
void
>
;
}
/**
* Options for creating an [AuthenticationProvider](#AuthentcationProvider).
*/
export
interface
AuthenticationProviderOptions
{
/**
* Whether it is possible to be signed into multiple accounts at once with this provider.
* If not specified, will default to false.
*/
readonly
supportsMultipleAccounts
?:
boolean
;
}
export
namespace
authentication
{
/**
* Register an authentication provider.
*
* There can only be one provider per id and an error is being thrown when an id
* has already been used by another provider.
* has already been used by another provider.
Ids are case-sensitive.
*
* @param id The unique identifier of the provider.
* @param label The human-readable name of the provider.
* @param provider The authentication provider provider.
* @params options Additional options for the provider.
* @return A [disposable](#Disposable) that unregisters this provider when being disposed.
*/
export
function
registerAuthenticationProvider
(
provider
:
AuthenticationProvider
):
Disposable
;
export
function
registerAuthenticationProvider
(
id
:
string
,
label
:
string
,
provider
:
AuthenticationProvider
,
options
?:
AuthenticationProviderOptions
):
Disposable
;
/**
* @deprecated - getSession should now trigger extension activation.
...
...
src/vs/workbench/api/common/extHost.api.impl.ts
浏览文件 @
c8529766
...
...
@@ -214,9 +214,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
get
onDidChangeSessions
():
Event
<
vscode
.
AuthenticationSessionsChangeEvent
>
{
return
extHostAuthentication
.
onDidChangeSessions
;
},
registerAuthenticationProvider
(
provider
:
vscode
.
AuthenticationProvider
):
vscode
.
Disposable
{
registerAuthenticationProvider
(
id
:
string
,
label
:
string
,
provider
:
vscode
.
AuthenticationProvider
,
options
?:
vscode
.
AuthenticationProviderOptions
):
vscode
.
Disposable
{
checkProposedApiEnabled
(
extension
);
return
extHostAuthentication
.
registerAuthenticationProvider
(
provider
);
return
extHostAuthentication
.
registerAuthenticationProvider
(
id
,
label
,
provider
,
options
);
},
get
onDidChangeAuthenticationProviders
():
Event
<
vscode
.
AuthenticationProvidersChangeEvent
>
{
checkProposedApiEnabled
(
extension
);
...
...
src/vs/workbench/api/common/extHostAuthentication.ts
浏览文件 @
c8529766
...
...
@@ -15,11 +15,15 @@ interface GetSessionsRequest {
result
:
Promise
<
vscode
.
AuthenticationSession
|
undefined
>
;
}
interface
ProviderWithMetadata
{
label
:
string
;
provider
:
vscode
.
AuthenticationProvider
;
options
:
vscode
.
AuthenticationProviderOptions
;
}
export
class
ExtHostAuthentication
implements
ExtHostAuthenticationShape
{
private
_proxy
:
MainThreadAuthenticationShape
;
private
_authenticationProviders
:
Map
<
string
,
vscode
.
AuthenticationProvider
>
=
new
Map
<
string
,
vscode
.
AuthenticationProvider
>
();
private
_providerIds
:
string
[]
=
[];
private
_authenticationProviders
:
Map
<
string
,
ProviderWithMetadata
>
=
new
Map
<
string
,
ProviderWithMetadata
>
();
private
_providers
:
vscode
.
AuthenticationProviderInformation
[]
=
[];
...
...
@@ -79,128 +83,120 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
private
async
_getSession
(
requestingExtension
:
IExtensionDescription
,
extensionId
:
string
,
providerId
:
string
,
scopes
:
string
[],
options
:
vscode
.
AuthenticationGetSessionOptions
=
{}):
Promise
<
vscode
.
AuthenticationSession
|
undefined
>
{
await
this
.
_proxy
.
$ensureProvider
(
providerId
);
const
provider
=
this
.
_authenticationProviders
.
get
(
providerId
);
const
provider
Data
=
this
.
_authenticationProviders
.
get
(
providerId
);
const
extensionName
=
requestingExtension
.
displayName
||
requestingExtension
.
name
;
if
(
!
provider
)
{
if
(
!
provider
Data
)
{
return
this
.
_proxy
.
$getSession
(
providerId
,
scopes
,
extensionId
,
extensionName
,
options
);
}
const
orderedScopes
=
scopes
.
sort
().
join
(
'
'
);
const
sessions
=
(
await
provider
.
getSessions
()).
filter
(
session
=>
session
.
scopes
.
slice
().
sort
().
join
(
'
'
)
===
orderedScopes
);
const
sessions
=
(
await
provider
Data
.
provider
.
getSessions
()).
filter
(
session
=>
session
.
scopes
.
slice
().
sort
().
join
(
'
'
)
===
orderedScopes
);
let
session
:
vscode
.
AuthenticationSession
|
undefined
=
undefined
;
if
(
sessions
.
length
)
{
if
(
!
provider
.
supportsMultipleAccounts
)
{
if
(
!
provider
Data
.
options
.
supportsMultipleAccounts
)
{
session
=
sessions
[
0
];
const
allowed
=
await
this
.
_proxy
.
$getSessionsPrompt
(
providerId
,
session
.
account
.
label
,
provider
.
label
,
extensionId
,
extensionName
);
const
allowed
=
await
this
.
_proxy
.
$getSessionsPrompt
(
providerId
,
session
.
account
.
label
,
provider
Data
.
label
,
extensionId
,
extensionName
);
if
(
!
allowed
)
{
throw
new
Error
(
'
User did not consent to login.
'
);
}
}
else
{
// On renderer side, confirm consent, ask user to choose between accounts if multiple sessions are valid
const
selected
=
await
this
.
_proxy
.
$selectSession
(
providerId
,
provider
.
label
,
extensionId
,
extensionName
,
sessions
,
scopes
,
!!
options
.
clearSessionPreference
);
const
selected
=
await
this
.
_proxy
.
$selectSession
(
providerId
,
provider
Data
.
label
,
extensionId
,
extensionName
,
sessions
,
scopes
,
!!
options
.
clearSessionPreference
);
session
=
sessions
.
find
(
session
=>
session
.
id
===
selected
.
id
);
}
}
else
{
if
(
options
.
createIfNone
)
{
const
isAllowed
=
await
this
.
_proxy
.
$loginPrompt
(
provider
.
label
,
extensionName
);
const
isAllowed
=
await
this
.
_proxy
.
$loginPrompt
(
provider
Data
.
label
,
extensionName
);
if
(
!
isAllowed
)
{
throw
new
Error
(
'
User did not consent to login.
'
);
}
session
=
await
provider
.
login
(
scopes
);
session
=
await
provider
Data
.
provider
.
login
(
scopes
);
await
this
.
_proxy
.
$setTrustedExtensionAndAccountPreference
(
providerId
,
session
.
account
.
label
,
extensionId
,
extensionName
,
session
.
id
);
}
else
{
await
this
.
_proxy
.
$requestNewSession
(
providerId
,
scopes
,
extensionId
,
extensionName
);
}
}
return
session
;
}
async
logout
(
providerId
:
string
,
sessionId
:
string
):
Promise
<
void
>
{
const
provider
=
this
.
_authenticationProviders
.
get
(
providerId
);
if
(
!
provider
)
{
const
provider
Data
=
this
.
_authenticationProviders
.
get
(
providerId
);
if
(
!
provider
Data
)
{
return
this
.
_proxy
.
$logout
(
providerId
,
sessionId
);
}
return
provider
.
logout
(
sessionId
);
return
provider
Data
.
provider
.
logout
(
sessionId
);
}
registerAuthenticationProvider
(
provider
:
vscode
.
AuthenticationProvider
):
vscode
.
Disposable
{
if
(
this
.
_authenticationProviders
.
get
(
provider
.
id
))
{
throw
new
Error
(
`An authentication provider with id '
${
provider
.
id
}
' is already registered.`
);
registerAuthenticationProvider
(
id
:
string
,
label
:
string
,
provider
:
vscode
.
AuthenticationProvider
,
options
?:
vscode
.
AuthenticationProviderOptions
):
vscode
.
Disposable
{
if
(
this
.
_authenticationProviders
.
get
(
id
))
{
throw
new
Error
(
`An authentication provider with id '
${
id
}
' is already registered.`
);
}
this
.
_authenticationProviders
.
set
(
provider
.
id
,
provider
);
if
(
!
this
.
_providerIds
.
includes
(
provider
.
id
))
{
this
.
_providerIds
.
push
(
provider
.
id
);
}
this
.
_authenticationProviders
.
set
(
id
,
{
label
,
provider
,
options
:
options
??
{
supportsMultipleAccounts
:
false
}
});
if
(
!
this
.
_providers
.
find
(
p
=>
p
.
id
===
provider
.
id
))
{
if
(
!
this
.
_providers
.
find
(
p
=>
p
.
id
===
id
))
{
this
.
_providers
.
push
({
id
:
provider
.
id
,
label
:
provider
.
label
id
:
id
,
label
:
label
});
}
const
listener
=
provider
.
onDidChangeSessions
(
e
=>
{
this
.
_proxy
.
$sendDidChangeSessions
(
provider
.
id
,
e
);
this
.
_proxy
.
$sendDidChangeSessions
(
id
,
e
);
});
this
.
_proxy
.
$registerAuthenticationProvider
(
provider
.
id
,
provider
.
label
,
provider
.
supportsMultipleAccounts
);
this
.
_proxy
.
$registerAuthenticationProvider
(
id
,
label
,
options
?.
supportsMultipleAccounts
??
false
);
return
new
Disposable
(()
=>
{
listener
.
dispose
();
this
.
_authenticationProviders
.
delete
(
provider
.
id
);
const
index
=
this
.
_providerIds
.
findIndex
(
id
=>
id
===
provider
.
id
);
if
(
index
>
-
1
)
{
this
.
_providerIds
.
splice
(
index
);
}
this
.
_authenticationProviders
.
delete
(
id
);
const
i
=
this
.
_providers
.
findIndex
(
p
=>
p
.
id
===
provider
.
id
);
const
i
=
this
.
_providers
.
findIndex
(
p
=>
p
.
id
===
id
);
if
(
i
>
-
1
)
{
this
.
_providers
.
splice
(
i
);
}
this
.
_proxy
.
$unregisterAuthenticationProvider
(
provider
.
id
);
this
.
_proxy
.
$unregisterAuthenticationProvider
(
id
);
});
}
$login
(
providerId
:
string
,
scopes
:
string
[]):
Promise
<
modes
.
AuthenticationSession
>
{
const
authProvider
=
this
.
_authenticationProviders
.
get
(
providerId
);
if
(
authProvider
)
{
return
Promise
.
resolve
(
authP
rovider
.
login
(
scopes
));
const
providerData
=
this
.
_authenticationProviders
.
get
(
providerId
);
if
(
providerData
)
{
return
Promise
.
resolve
(
providerData
.
p
rovider
.
login
(
scopes
));
}
throw
new
Error
(
`Unable to find authentication provider with handle:
${
providerId
}
`
);
}
$logout
(
providerId
:
string
,
sessionId
:
string
):
Promise
<
void
>
{
const
authProvider
=
this
.
_authenticationProviders
.
get
(
providerId
);
if
(
authProvider
)
{
return
Promise
.
resolve
(
authP
rovider
.
logout
(
sessionId
));
const
providerData
=
this
.
_authenticationProviders
.
get
(
providerId
);
if
(
providerData
)
{
return
Promise
.
resolve
(
providerData
.
p
rovider
.
logout
(
sessionId
));
}
throw
new
Error
(
`Unable to find authentication provider with handle:
${
providerId
}
`
);
}
$getSessions
(
providerId
:
string
):
Promise
<
ReadonlyArray
<
modes
.
AuthenticationSession
>>
{
const
authProvider
=
this
.
_authenticationProviders
.
get
(
providerId
);
if
(
authProvider
)
{
return
Promise
.
resolve
(
authP
rovider
.
getSessions
());
const
providerData
=
this
.
_authenticationProviders
.
get
(
providerId
);
if
(
providerData
)
{
return
Promise
.
resolve
(
providerData
.
p
rovider
.
getSessions
());
}
throw
new
Error
(
`Unable to find authentication provider with handle:
${
providerId
}
`
);
}
async
$getSessionAccessToken
(
providerId
:
string
,
sessionId
:
string
):
Promise
<
string
>
{
const
authProvider
=
this
.
_authenticationProviders
.
get
(
providerId
);
if
(
authProvider
)
{
const
sessions
=
await
authP
rovider
.
getSessions
();
const
providerData
=
this
.
_authenticationProviders
.
get
(
providerId
);
if
(
providerData
)
{
const
sessions
=
await
providerData
.
p
rovider
.
getSessions
();
const
session
=
sessions
.
find
(
session
=>
session
.
id
===
sessionId
);
if
(
session
)
{
return
session
.
accessToken
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录