Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
b80e8133
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,发现更多精彩内容 >>
提交
b80e8133
编写于
1月 15, 2020
作者:
R
Rachel Macfarlane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updates to authentication provider API
上级
2dcd10f9
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
173 addition
and
127 deletion
+173
-127
extensions/vscode-account/src/AADHelper.ts
extensions/vscode-account/src/AADHelper.ts
+6
-6
extensions/vscode-account/src/extension.ts
extensions/vscode-account/src/extension.ts
+4
-4
extensions/vscode-account/src/vscode.proposed.d.ts
extensions/vscode-account/src/vscode.proposed.d.ts
+28
-8
src/vs/editor/common/modes.ts
src/vs/editor/common/modes.ts
+1
-12
src/vs/vscode.proposed.d.ts
src/vs/vscode.proposed.d.ts
+28
-8
src/vs/workbench/api/browser/mainThreadAuthentication.ts
src/vs/workbench/api/browser/mainThreadAuthentication.ts
+12
-26
src/vs/workbench/api/common/extHost.api.impl.ts
src/vs/workbench/api/common/extHost.api.impl.ts
+18
-0
src/vs/workbench/api/common/extHost.protocol.ts
src/vs/workbench/api/common/extHost.protocol.ts
+6
-7
src/vs/workbench/api/common/extHostAuthentication.ts
src/vs/workbench/api/common/extHostAuthentication.ts
+47
-29
src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts
...vs/workbench/contrib/userDataSync/browser/userDataSync.ts
+11
-10
src/vs/workbench/services/authentication/browser/authenticationService.ts
.../services/authentication/browser/authenticationService.ts
+12
-17
未找到文件。
extensions/vscode-account/src/AADHelper.ts
浏览文件 @
b80e8133
...
...
@@ -23,7 +23,7 @@ interface IToken {
refreshToken
:
string
;
}
export
const
onDidChange
Accounts
=
new
vscode
.
EventEmitter
<
vscode
.
Account
[]
>
();
export
const
onDidChange
Sessions
=
new
vscode
.
EventEmitter
<
void
>
();
export
class
AzureActiveDirectoryService
{
private
_token
:
IToken
|
undefined
;
...
...
@@ -44,20 +44,20 @@ export class AzureActiveDirectoryService {
// Another window has logged in, generate access token for this instance.
if
(
refreshToken
&&
!
this
.
_token
)
{
await
this
.
refreshToken
(
refreshToken
);
onDidChange
Accounts
.
fire
(
this
.
accounts
);
onDidChange
Sessions
.
fire
(
);
}
// Another window has logged out
if
(
!
refreshToken
&&
this
.
_token
)
{
await
this
.
logout
();
onDidChange
Accounts
.
fire
(
this
.
accounts
);
onDidChange
Sessions
.
fire
(
);
}
this
.
pollForChange
();
},
1000
*
30
);
}
private
tokenToAccount
(
token
:
IToken
):
vscode
.
Account
{
private
tokenToAccount
(
token
:
IToken
):
vscode
.
Session
{
return
{
id
:
''
,
accessToken
:
token
.
accessToken
,
...
...
@@ -77,7 +77,7 @@ export class AzureActiveDirectoryService {
return
displayName
;
}
get
accounts
():
vscode
.
Account
[]
{
get
sessions
():
vscode
.
Session
[]
{
return
this
.
_token
?
[
this
.
tokenToAccount
(
this
.
_token
)]
:
[];
}
...
...
@@ -146,7 +146,7 @@ export class AzureActiveDirectoryService {
}
catch
(
e
)
{
await
this
.
logout
();
}
finally
{
onDidChange
Accounts
.
fire
(
this
.
accounts
);
onDidChange
Sessions
.
fire
(
);
}
},
1000
*
(
parseInt
(
token
.
expiresIn
)
-
10
));
...
...
extensions/vscode-account/src/extension.ts
浏览文件 @
b80e8133
...
...
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import
*
as
vscode
from
'
vscode
'
;
import
{
AzureActiveDirectoryService
,
onDidChange
Account
s
}
from
'
./AADHelper
'
;
import
{
AzureActiveDirectoryService
,
onDidChange
Session
s
}
from
'
./AADHelper
'
;
export
async
function
activate
(
context
:
vscode
.
ExtensionContext
)
{
...
...
@@ -15,12 +15,12 @@ export async function activate(context: vscode.ExtensionContext) {
vscode
.
authentication
.
registerAuthenticationProvider
({
id
:
'
MSA
'
,
displayName
:
'
Microsoft Account
'
,
// TODO localize
onDidChange
Accounts
:
onDidChangeAccount
s
.
event
,
get
Accounts
:
()
=>
Promise
.
resolve
(
loginService
.
account
s
),
onDidChange
Sessions
:
onDidChangeSession
s
.
event
,
get
Sessions
:
()
=>
Promise
.
resolve
(
loginService
.
session
s
),
login
:
async
()
=>
{
try
{
await
loginService
.
login
();
return
loginService
.
account
s
[
0
]
!
;
return
loginService
.
session
s
[
0
]
!
;
}
catch
(
e
)
{
vscode
.
window
.
showErrorMessage
(
`Logging in failed:
${
e
}
`
);
throw
e
;
...
...
extensions/vscode-account/src/vscode.proposed.d.ts
浏览文件 @
b80e8133
...
...
@@ -16,25 +16,45 @@
declare
module
'
vscode
'
{
export
interface
Account
{
readonly
id
:
string
;
readonly
accessToken
:
string
;
readonly
displayName
:
string
;
export
interface
Session
{
id
:
string
;
accessToken
:
string
;
displayName
:
string
;
}
export
interface
AuthenticationProvider
{
readonly
id
:
string
;
readonly
displayName
:
string
;
readonly
onDidChangeSessions
:
Event
<
void
>
;
getAccounts
():
Promise
<
ReadonlyArray
<
Account
>>
;
readonly
onDidChangeAccounts
:
Event
<
ReadonlyArray
<
Account
>>
;
/**
* Returns an array of current sessions.
*/
getSessions
():
Promise
<
ReadonlyArray
<
Session
>>
;
login
():
Promise
<
Account
>
;
logout
(
accountId
:
string
):
Promise
<
void
>
;
/**
* Prompts a user to login.
*/
login
():
Promise
<
Session
>
;
logout
(
sessionId
:
string
):
Promise
<
void
>
;
}
export
namespace
authentication
{
export
function
registerAuthenticationProvider
(
provider
:
AuthenticationProvider
):
Disposable
;
/**
* Fires with the provider id that was registered or unregistered.
*/
export
const
onDidRegisterAuthenticationProvider
:
Event
<
string
>
;
export
const
onDidUnregisterAuthenticationProvider
:
Event
<
string
>
;
/**
* Fires with the provider id that changed sessions.
*/
export
const
onDidChangeSessions
:
Event
<
string
>
;
export
function
login
(
providerId
:
string
):
Promise
<
Session
>
;
export
function
logout
(
providerId
:
string
,
accountId
:
string
):
Promise
<
void
>
;
export
function
getSessions
(
providerId
:
string
):
Promise
<
ReadonlyArray
<
Session
>
|
undefined
>
;
}
// #region Ben - extension auth flow (desktop+web)
...
...
src/vs/editor/common/modes.ts
浏览文件 @
b80e8133
...
...
@@ -1283,23 +1283,12 @@ export interface RenameProvider {
/**
* @internal
*/
export
interface
Account
{
export
interface
Session
{
id
:
string
;
accessToken
:
string
;
displayName
:
string
;
}
/**
* @internal
*/
export
interface
AuthenticationProvider
{
getAccount
():
Promise
<
Account
|
undefined
>
;
onDidChangeAccount
:
Event
<
Account
>
;
login
():
Promise
<
Account
>
;
logout
(
accountId
:
string
):
Promise
<
void
>
;
}
export
interface
Command
{
id
:
string
;
title
:
string
;
...
...
src/vs/vscode.proposed.d.ts
浏览文件 @
b80e8133
...
...
@@ -16,25 +16,45 @@
declare
module
'
vscode
'
{
export
interface
Account
{
readonly
id
:
string
;
readonly
accessToken
:
string
;
readonly
displayName
:
string
;
export
interface
Session
{
id
:
string
;
accessToken
:
string
;
displayName
:
string
;
}
export
interface
AuthenticationProvider
{
readonly
id
:
string
;
readonly
displayName
:
string
;
readonly
onDidChangeSessions
:
Event
<
void
>
;
getAccounts
():
Promise
<
ReadonlyArray
<
Account
>>
;
readonly
onDidChangeAccounts
:
Event
<
ReadonlyArray
<
Account
>>
;
/**
* Returns an array of current sessions.
*/
getSessions
():
Promise
<
ReadonlyArray
<
Session
>>
;
login
():
Promise
<
Account
>
;
logout
(
accountId
:
string
):
Promise
<
void
>
;
/**
* Prompts a user to login.
*/
login
():
Promise
<
Session
>
;
logout
(
sessionId
:
string
):
Promise
<
void
>
;
}
export
namespace
authentication
{
export
function
registerAuthenticationProvider
(
provider
:
AuthenticationProvider
):
Disposable
;
/**
* Fires with the provider id that was registered or unregistered.
*/
export
const
onDidRegisterAuthenticationProvider
:
Event
<
string
>
;
export
const
onDidUnregisterAuthenticationProvider
:
Event
<
string
>
;
/**
* Fires with the provider id that changed sessions.
*/
export
const
onDidChangeSessions
:
Event
<
string
>
;
export
function
login
(
providerId
:
string
):
Promise
<
Session
>
;
export
function
logout
(
providerId
:
string
,
accountId
:
string
):
Promise
<
void
>
;
export
function
getSessions
(
providerId
:
string
):
Promise
<
ReadonlyArray
<
Session
>>
;
}
//#region Alex - resolvers
...
...
src/vs/workbench/api/browser/mainThreadAuthentication.ts
浏览文件 @
b80e8133
...
...
@@ -10,32 +10,27 @@ import { IAuthenticationService } from 'vs/workbench/services/authentication/bro
import
{
ExtHostAuthenticationShape
,
ExtHostContext
,
IExtHostContext
,
MainContext
,
MainThreadAuthenticationShape
}
from
'
../common/extHost.protocol
'
;
export
class
MainThreadAuthenticationProvider
{
public
readonly
handle
:
number
;
constructor
(
private
readonly
_proxy
:
ExtHostAuthenticationShape
,
public
readonly
id
:
string
,
handle
:
number
)
{
this
.
handle
=
handle
;
}
public
readonly
id
:
string
)
{
}
accounts
():
Promise
<
ReadonlyArray
<
modes
.
Account
>>
{
return
this
.
_proxy
.
$
accounts
(
this
.
handle
);
getSessions
():
Promise
<
ReadonlyArray
<
modes
.
Session
>>
{
return
this
.
_proxy
.
$
getSessions
(
this
.
id
);
}
login
():
Promise
<
modes
.
Account
>
{
return
this
.
_proxy
.
$login
(
this
.
handle
);
login
():
Promise
<
modes
.
Session
>
{
return
this
.
_proxy
.
$login
(
this
.
id
);
}
logout
(
accountId
:
string
):
Promise
<
void
>
{
return
this
.
_proxy
.
$logout
(
this
.
handle
,
accountId
);
return
this
.
_proxy
.
$logout
(
this
.
id
,
accountId
);
}
}
@
extHostNamedCustomer
(
MainContext
.
MainThreadAuthentication
)
export
class
MainThreadAuthentication
extends
Disposable
implements
MainThreadAuthenticationShape
{
private
readonly
_proxy
:
ExtHostAuthenticationShape
;
private
_handlers
=
new
Map
<
number
,
string
>
();
constructor
(
extHostContext
:
IExtHostContext
,
...
...
@@ -45,25 +40,16 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
this
.
_proxy
=
extHostContext
.
getProxy
(
ExtHostContext
.
ExtHostAuthentication
);
}
$registerAuthenticationProvider
(
handle
:
number
,
id
:
string
):
void
{
const
provider
=
new
MainThreadAuthenticationProvider
(
this
.
_proxy
,
id
,
handle
);
this
.
_handlers
.
set
(
handle
,
id
);
$registerAuthenticationProvider
(
id
:
string
):
void
{
const
provider
=
new
MainThreadAuthenticationProvider
(
this
.
_proxy
,
id
);
this
.
authenticationService
.
registerAuthenticationProvider
(
id
,
provider
);
}
$unregisterAuthenticationProvider
(
handle
:
number
):
void
{
const
id
=
this
.
_handlers
.
get
(
handle
);
if
(
!
id
)
{
throw
new
Error
(
`No authentication provider registered with id
${
id
}
`
);
}
$unregisterAuthenticationProvider
(
id
:
string
):
void
{
this
.
authenticationService
.
unregisterAuthenticationProvider
(
id
);
}
$onDidChangeAccounts
(
handle
:
number
,
accounts
:
ReadonlyArray
<
modes
.
Account
>
)
{
const
id
=
this
.
_handlers
.
get
(
handle
);
if
(
id
)
{
this
.
authenticationService
.
accountsUpdate
(
id
,
accounts
);
}
$onDidChangeSessions
(
id
:
string
)
{
this
.
authenticationService
.
sessionsUpdate
(
id
);
}
}
src/vs/workbench/api/common/extHost.api.impl.ts
浏览文件 @
b80e8133
...
...
@@ -182,6 +182,24 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
const
authentication
:
typeof
vscode
.
authentication
=
{
registerAuthenticationProvider
(
provider
:
vscode
.
AuthenticationProvider
):
vscode
.
Disposable
{
return
extHostAuthentication
.
registerAuthenticationProvider
(
provider
);
},
login
(
providerId
:
string
):
Promise
<
vscode
.
Session
>
{
return
extHostAuthentication
.
$login
(
providerId
);
},
logout
(
providerId
:
string
,
accountId
:
string
):
Promise
<
void
>
{
return
extHostAuthentication
.
$logout
(
providerId
,
accountId
);
},
getSessions
(
providerId
:
string
):
Promise
<
ReadonlyArray
<
vscode
.
Session
>>
{
return
extHostAuthentication
.
$getSessions
(
providerId
);
},
get
onDidChangeSessions
()
{
return
extHostAuthentication
.
onDidChangeSessions
;
},
get
onDidRegisterAuthenticationProvider
()
{
return
extHostAuthentication
.
onDidRegisterAuthenticationProvider
;
},
get
onDidUnregisterAuthenticationProvider
()
{
return
extHostAuthentication
.
onDidUnregisterAuthenticationProvider
;
}
};
...
...
src/vs/workbench/api/common/extHost.protocol.ts
浏览文件 @
b80e8133
...
...
@@ -148,9 +148,9 @@ export interface MainThreadCommentsShape extends IDisposable {
}
export
interface
MainThreadAuthenticationShape
extends
IDisposable
{
$registerAuthenticationProvider
(
handle
:
number
,
id
:
string
):
void
;
$unregisterAuthenticationProvider
(
handle
:
number
):
void
;
$onDidChange
Accounts
(
handle
:
number
,
accounts
:
ReadonlyArray
<
modes
.
Account
>
):
void
;
$registerAuthenticationProvider
(
id
:
string
):
void
;
$unregisterAuthenticationProvider
(
id
:
string
):
void
;
$onDidChange
Sessions
(
id
:
string
):
void
;
}
export
interface
MainThreadConfigurationShape
extends
IDisposable
{
...
...
@@ -898,10 +898,9 @@ export interface ExtHostLabelServiceShape {
}
export
interface
ExtHostAuthenticationShape
{
$accounts
(
handle
:
number
):
Promise
<
ReadonlyArray
<
modes
.
Account
>>
;
$login
(
handle
:
number
):
Promise
<
modes
.
Account
>
;
$logout
(
handle
:
number
,
accountId
:
string
):
Promise
<
void
>
;
// TODO rmacfarlane
$getSessions
(
id
:
string
):
Promise
<
ReadonlyArray
<
modes
.
Session
>>
;
$login
(
id
:
string
):
Promise
<
modes
.
Session
>
;
$logout
(
id
:
string
,
accountId
:
string
):
Promise
<
void
>
;
}
export
interface
ExtHostSearchShape
{
...
...
src/vs/workbench/api/common/extHostAuthentication.ts
浏览文件 @
b80e8133
...
...
@@ -9,75 +9,93 @@ import { Emitter, Event } from 'vs/base/common/event';
import
{
IMainContext
,
MainContext
,
MainThreadAuthenticationShape
,
ExtHostAuthenticationShape
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
const
_onDidUnregisterAuthenticationProvider
=
new
Emitter
<
string
>
();
const
_onDidChangeSessions
=
new
Emitter
<
string
>
();
export
class
ExtHostAuthenticationProvider
implements
IDisposable
{
constructor
(
private
_provider
:
vscode
.
AuthenticationProvider
,
private
readonly
_handle
:
number
,
private
_id
:
string
,
private
_proxy
:
MainThreadAuthenticationShape
)
{
this
.
_provider
.
onDidChangeAccounts
(
x
=>
this
.
_proxy
.
$onDidChangeAccounts
(
this
.
_handle
,
x
));
this
.
_provider
.
onDidChangeSessions
(
x
=>
{
this
.
_proxy
.
$onDidChangeSessions
(
this
.
_id
);
_onDidChangeSessions
.
fire
(
this
.
_id
);
});
}
get
Accounts
():
Promise
<
ReadonlyArray
<
vscode
.
Account
>>
{
return
this
.
_provider
.
get
Account
s
();
get
Sessions
():
Promise
<
ReadonlyArray
<
vscode
.
Session
>>
{
return
this
.
_provider
.
get
Session
s
();
}
login
():
Promise
<
vscode
.
Account
>
{
login
():
Promise
<
vscode
.
Session
>
{
return
this
.
_provider
.
login
();
}
logout
(
account
Id
:
string
):
Promise
<
void
>
{
return
this
.
_provider
.
logout
(
account
Id
);
logout
(
session
Id
:
string
):
Promise
<
void
>
{
return
this
.
_provider
.
logout
(
session
Id
);
}
dispose
():
void
{
this
.
_proxy
.
$unregisterAuthenticationProvider
(
this
.
_handle
);
this
.
_proxy
.
$unregisterAuthenticationProvider
(
this
.
_id
);
_onDidUnregisterAuthenticationProvider
.
fire
(
this
.
_id
);
}
}
export
class
ExtHostAuthentication
implements
ExtHostAuthenticationShape
{
public
static
_handlePool
:
number
=
0
;
private
_proxy
:
MainThreadAuthenticationShape
;
private
_authenticationProviders
:
Map
<
number
,
ExtHostAuthenticationProvider
>
=
new
Map
<
number
,
ExtHostAuthenticationProvider
>
();
private
_authenticationProviders
:
Map
<
string
,
ExtHostAuthenticationProvider
>
=
new
Map
<
string
,
ExtHostAuthenticationProvider
>
();
private
_onDidRegisterAuthenticationProvider
=
new
Emitter
<
string
>
();
readonly
onDidRegisterAuthenticationProvider
:
Event
<
string
>
=
this
.
_onDidRegisterAuthenticationProvider
.
event
;
readonly
onDidUnregisterAuthenticationProvider
:
Event
<
string
>
=
_onDidUnregisterAuthenticationProvider
.
event
;
readonly
onDidChangeSessions
:
Event
<
string
>
=
_onDidChangeSessions
.
event
;
constructor
(
mainContext
:
IMainContext
)
{
this
.
_proxy
=
mainContext
.
getProxy
(
MainContext
.
MainThreadAuthentication
);
}
private
readonly
_onDidRefreshToken
=
new
Emitter
<
any
>
();
readonly
onDidRefreshToken
:
Event
<
any
>
=
this
.
_onDidRefreshToken
.
event
;
this
.
onDidUnregisterAuthenticationProvider
(
providerId
=>
{
this
.
_authenticationProviders
.
delete
(
providerId
);
});
}
registerAuthenticationProvider
(
provider
:
vscode
.
AuthenticationProvider
)
{
const
handle
=
ExtHostAuthentication
.
_handlePool
++
;
const
authenticationProvider
=
new
ExtHostAuthenticationProvider
(
provider
,
handle
,
this
.
_proxy
);
this
.
_authenticationProviders
.
set
(
handle
,
authenticationProvider
);
if
(
this
.
_authenticationProviders
.
get
(
provider
.
id
))
{
throw
new
Error
(
`An authentication provider with id '
${
provider
.
id
}
' is already registered.`
);
}
const
authenticationProvider
=
new
ExtHostAuthenticationProvider
(
provider
,
provider
.
id
,
this
.
_proxy
);
this
.
_authenticationProviders
.
set
(
provider
.
id
,
authenticationProvider
);
this
.
_proxy
.
$registerAuthenticationProvider
(
handle
,
provider
.
id
);
this
.
_proxy
.
$registerAuthenticationProvider
(
provider
.
id
);
this
.
_onDidRegisterAuthenticationProvider
.
fire
(
provider
.
id
);
return
authenticationProvider
;
}
$
accounts
(
handle
:
number
):
Promise
<
ReadonlyArray
<
modes
.
Account
>
>
{
const
authProvider
=
this
.
_authenticationProviders
.
get
(
handle
);
$
login
(
providerId
:
string
):
Promise
<
modes
.
Session
>
{
const
authProvider
=
this
.
_authenticationProviders
.
get
(
providerId
);
if
(
authProvider
)
{
return
Promise
.
resolve
(
authProvider
.
getAccounts
());
return
Promise
.
resolve
(
authProvider
.
login
());
}
throw
new
Error
(
`Unable to find authentication provider with handle:
${
handle
}
`
);
throw
new
Error
(
`Unable to find authentication provider with handle:
${
0
}
`
);
}
$log
in
(
handle
:
number
):
Promise
<
modes
.
Account
>
{
const
authProvider
=
this
.
_authenticationProviders
.
get
(
handle
);
$log
out
(
providerId
:
string
,
sessionId
:
string
):
Promise
<
void
>
{
const
authProvider
=
this
.
_authenticationProviders
.
get
(
providerId
);
if
(
authProvider
)
{
return
authProvider
.
login
(
);
return
Promise
.
resolve
(
authProvider
.
logout
(
sessionId
)
);
}
throw
new
Error
(
`Unable to find authentication provider with handle:
${
handle
}
`
);
throw
new
Error
(
`Unable to find authentication provider with handle:
${
0
}
`
);
}
$
logout
(
handle
:
number
,
accountId
:
string
):
Promise
<
void
>
{
const
authProvider
=
this
.
_authenticationProviders
.
get
(
handle
);
$
getSessions
(
providerId
:
string
):
Promise
<
ReadonlyArray
<
modes
.
Session
>
>
{
const
authProvider
=
this
.
_authenticationProviders
.
get
(
providerId
);
if
(
authProvider
)
{
return
authProvider
.
logout
(
accountId
);
return
Promise
.
resolve
(
authProvider
.
getSessions
()
);
}
throw
new
Error
(
`Unable to find authentication provider with handle:
${
handle
}
`
);
throw
new
Error
(
`Unable to find authentication provider with handle:
${
0
}
`
);
}
}
src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts
浏览文件 @
b80e8133
...
...
@@ -33,8 +33,8 @@ import { UserDataSyncTrigger } from 'vs/workbench/contrib/userDataSync/browser/u
import
{
timeout
}
from
'
vs/base/common/async
'
;
import
{
IOutputService
}
from
'
vs/workbench/contrib/output/common/output
'
;
import
*
as
Constants
from
'
vs/workbench/contrib/logs/common/logConstants
'
;
import
{
IAuthenticationService
,
ChangeAccountEventData
}
from
'
vs/workbench/services/authentication/browser/authenticationService
'
;
import
{
Account
}
from
'
vs/editor/common/modes
'
;
import
{
IAuthenticationService
}
from
'
vs/workbench/services/authentication/browser/authenticationService
'
;
import
{
Session
}
from
'
vs/editor/common/modes
'
;
import
{
isPromiseCanceledError
}
from
'
vs/base/common/errors
'
;
const
enum
MSAAuthStatus
{
...
...
@@ -58,7 +58,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
private
readonly
badgeDisposable
=
this
.
_register
(
new
MutableDisposable
());
private
readonly
conflictsWarningDisposable
=
this
.
_register
(
new
MutableDisposable
());
private
readonly
signInNotificationDisposable
=
this
.
_register
(
new
MutableDisposable
());
private
_activeAccount
:
Account
|
undefined
;
private
_activeAccount
:
Session
|
undefined
;
constructor
(
@
IUserDataSyncService
private
readonly
userDataSyncService
:
IUserDataSyncService
,
...
...
@@ -89,7 +89,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
this
.
_register
(
Event
.
filter
(
this
.
configurationService
.
onDidChangeConfiguration
,
e
=>
e
.
affectsConfiguration
(
UserDataSyncWorkbenchContribution
.
ENABLEMENT_SETTING
))(()
=>
this
.
onDidChangeEnablement
()));
this
.
_register
(
this
.
authenticationService
.
onDidRegisterAuthenticationProvider
(
e
=>
this
.
onDidRegisterAuthenticationProvider
(
e
)));
this
.
_register
(
this
.
authenticationService
.
onDidUnregisterAuthenticationProvider
(
e
=>
this
.
onDidUnregisterAuthenticationProvider
(
e
)));
this
.
_register
(
this
.
authenticationService
.
onDidChange
Accounts
(
e
=>
this
.
onDidChangeAccount
s
(
e
)));
this
.
_register
(
this
.
authenticationService
.
onDidChange
Sessions
(
e
=>
this
.
onDidChangeSession
s
(
e
)));
this
.
registerActions
();
this
.
initializeActiveAccount
().
then
(
_
=>
{
if
(
isWeb
)
{
...
...
@@ -102,7 +102,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
}
private
async
initializeActiveAccount
():
Promise
<
void
>
{
const
accounts
=
await
this
.
authenticationService
.
get
Account
s
(
MSA
);
const
accounts
=
await
this
.
authenticationService
.
get
Session
s
(
MSA
);
// MSA provider has not yet been registered
if
(
!
accounts
)
{
return
;
...
...
@@ -130,11 +130,11 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
}
}
get
activeAccount
():
Account
|
undefined
{
get
activeAccount
():
Session
|
undefined
{
return
this
.
_activeAccount
;
}
set
activeAccount
(
account
:
Account
|
undefined
)
{
set
activeAccount
(
account
:
Session
|
undefined
)
{
this
.
_activeAccount
=
account
;
if
(
account
)
{
...
...
@@ -148,11 +148,12 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
this
.
updateBadge
();
}
private
onDidChangeAccounts
(
event
:
ChangeAccountEventData
):
void
{
if
(
event
.
providerId
===
MSA
)
{
private
async
onDidChangeSessions
(
providerId
:
string
):
Promise
<
void
>
{
if
(
providerId
===
MSA
)
{
if
(
this
.
activeAccount
)
{
// Try to update existing account, case where access token has been refreshed
const
matchingAccount
=
event
.
accounts
.
filter
(
a
=>
a
.
id
===
this
.
activeAccount
?.
id
)[
0
];
const
accounts
=
(
await
this
.
authenticationService
.
getSessions
(
MSA
)
||
[]);
const
matchingAccount
=
accounts
.
filter
(
a
=>
a
.
id
===
this
.
activeAccount
?.
id
)[
0
];
this
.
activeAccount
=
matchingAccount
;
}
else
{
this
.
initializeActiveAccount
();
...
...
src/vs/workbench/services/authentication/browser/authenticationService.ts
浏览文件 @
b80e8133
...
...
@@ -5,31 +5,26 @@
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
Account
}
from
'
vs/editor/common/modes
'
;
import
{
Session
}
from
'
vs/editor/common/modes
'
;
import
{
registerSingleton
}
from
'
vs/platform/instantiation/common/extensions
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
MainThreadAuthenticationProvider
}
from
'
vs/workbench/api/browser/mainThreadAuthentication
'
;
export
const
IAuthenticationService
=
createDecorator
<
IAuthenticationService
>
(
'
IAuthenticationService
'
);
export
interface
ChangeAccountEventData
{
providerId
:
string
;
accounts
:
ReadonlyArray
<
Account
>
;
}
export
interface
IAuthenticationService
{
_serviceBrand
:
undefined
;
registerAuthenticationProvider
(
id
:
string
,
provider
:
MainThreadAuthenticationProvider
):
void
;
unregisterAuthenticationProvider
(
id
:
string
):
void
;
accountsUpdate
(
providerId
:
string
,
accounts
:
ReadonlyArray
<
Account
>
):
void
;
sessionsUpdate
(
providerId
:
string
):
void
;
readonly
onDidRegisterAuthenticationProvider
:
Event
<
string
>
;
readonly
onDidUnregisterAuthenticationProvider
:
Event
<
string
>
;
readonly
onDidChange
Accounts
:
Event
<
ChangeAccountEventData
>
;
get
Accounts
(
providerId
:
string
):
Promise
<
ReadonlyArray
<
Account
>
|
undefined
>
;
login
(
providerId
:
string
):
Promise
<
Account
>
;
readonly
onDidChange
Sessions
:
Event
<
string
>
;
get
Sessions
(
providerId
:
string
):
Promise
<
ReadonlyArray
<
Session
>
|
undefined
>
;
login
(
providerId
:
string
):
Promise
<
Session
>
;
logout
(
providerId
:
string
,
accountId
:
string
):
Promise
<
void
>
;
}
...
...
@@ -44,8 +39,8 @@ export class AuthenticationService extends Disposable implements IAuthentication
private
_onDidUnregisterAuthenticationProvider
:
Emitter
<
string
>
=
this
.
_register
(
new
Emitter
<
string
>
());
readonly
onDidUnregisterAuthenticationProvider
:
Event
<
string
>
=
this
.
_onDidUnregisterAuthenticationProvider
.
event
;
private
_onDidChange
Accounts
:
Emitter
<
ChangeAccountEventData
>
=
this
.
_register
(
new
Emitter
<
ChangeAccountEventData
>
());
readonly
onDidChange
Accounts
:
Event
<
ChangeAccountEventData
>
=
this
.
_onDidChangeAccount
s
.
event
;
private
_onDidChange
Sessions
:
Emitter
<
string
>
=
this
.
_register
(
new
Emitter
<
string
>
());
readonly
onDidChange
Sessions
:
Event
<
string
>
=
this
.
_onDidChangeSession
s
.
event
;
constructor
()
{
super
();
...
...
@@ -61,20 +56,20 @@ export class AuthenticationService extends Disposable implements IAuthentication
this
.
_onDidUnregisterAuthenticationProvider
.
fire
(
id
);
}
accountsUpdate
(
providerId
:
string
,
accounts
:
ReadonlyArray
<
Account
>
):
void
{
this
.
_onDidChange
Accounts
.
fire
({
providerId
,
accounts
}
);
sessionsUpdate
(
id
:
string
):
void
{
this
.
_onDidChange
Sessions
.
fire
(
id
);
}
async
get
Accounts
(
id
:
string
):
Promise
<
ReadonlyArray
<
Account
>
|
undefined
>
{
async
get
Sessions
(
id
:
string
):
Promise
<
ReadonlyArray
<
Session
>
|
undefined
>
{
const
authProvider
=
this
.
_authenticationProviders
.
get
(
id
);
if
(
authProvider
)
{
return
await
authProvider
.
account
s
();
return
await
authProvider
.
getSession
s
();
}
return
undefined
;
}
async
login
(
id
:
string
):
Promise
<
Account
>
{
async
login
(
id
:
string
):
Promise
<
Session
>
{
const
authProvider
=
this
.
_authenticationProviders
.
get
(
id
);
if
(
authProvider
)
{
return
authProvider
.
login
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录