UNPKG

6.91 kBTypeScriptView Raw
1import { Event } from '../common/event';
2import { StorageService } from '../browser/storage-service';
3import { Disposable, DisposableCollection } from '../common/disposable';
4import { MenuModelRegistry } from '../common/menu';
5import { CommandRegistry } from '../common/command';
6export interface AuthenticationSessionAccountInformation {
7 readonly id: string;
8 readonly label: string;
9}
10export interface AuthenticationSession {
11 id: string;
12 accessToken: string;
13 account: AuthenticationSessionAccountInformation;
14 scopes: ReadonlyArray<string>;
15}
16export interface AuthenticationProviderInformation {
17 id: string;
18 label: string;
19}
20/** Should match the definition from the theia/vscode types */
21export interface AuthenticationProviderAuthenticationSessionsChangeEvent {
22 readonly added: readonly AuthenticationSession[] | undefined;
23 readonly removed: readonly AuthenticationSession[] | undefined;
24 readonly changed: readonly AuthenticationSession[] | undefined;
25}
26export interface SessionRequest {
27 disposables: Disposable[];
28 requestingExtensionIds: string[];
29}
30export interface SessionRequestInfo {
31 [scopes: string]: SessionRequest;
32}
33/**
34 * Our authentication provider should at least contain the following information:
35 * - The signature of authentication providers from vscode
36 * - Registration information about the provider (id, label)
37 * - Provider options (supportsMultipleAccounts)
38 *
39 * Additionally, we provide the possibility to sign out of a specific account name.
40 */
41export interface AuthenticationProvider {
42 id: string;
43 label: string;
44 supportsMultipleAccounts: boolean;
45 hasSessions(): boolean;
46 signOut(accountName: string): Promise<void>;
47 updateSessionItems(event: AuthenticationProviderAuthenticationSessionsChangeEvent): Promise<void>;
48 /**
49 * @deprecated use `createSession` instead.
50 */
51 login(scopes: string[]): Promise<AuthenticationSession>;
52 /**
53 * @deprecated use `removeSession` instead.
54 */
55 logout(sessionId: string): Promise<void>;
56 /**
57 * An [event](#Event) which fires when the array of sessions has changed, or data
58 * within a session has changed.
59 */
60 readonly onDidChangeSessions: Event<AuthenticationProviderAuthenticationSessionsChangeEvent>;
61 /**
62 * Get a list of sessions.
63 * @param scopes An optional list of scopes. If provided, the sessions returned should match
64 * these permissions, otherwise all sessions should be returned.
65 * @returns A promise that resolves to an array of authentication sessions.
66 */
67 getSessions(scopes?: string[]): Thenable<ReadonlyArray<AuthenticationSession>>;
68 /**
69 * Prompts a user to login.
70 * @param scopes A list of scopes, permissions, that the new session should be created with.
71 * @returns A promise that resolves to an authentication session.
72 */
73 createSession(scopes: string[]): Thenable<AuthenticationSession>;
74 /**
75 * Removes the session corresponding to session id.
76 * @param sessionId The id of the session to remove.
77 */
78 removeSession(sessionId: string): Thenable<void>;
79}
80export declare const AuthenticationService: unique symbol;
81export interface AuthenticationService {
82 isAuthenticationProviderRegistered(id: string): boolean;
83 getProviderIds(): string[];
84 registerAuthenticationProvider(id: string, provider: AuthenticationProvider): void;
85 unregisterAuthenticationProvider(id: string): void;
86 requestNewSession(id: string, scopes: string[], extensionId: string, extensionName: string): void;
87 updateSessions(providerId: string, event: AuthenticationProviderAuthenticationSessionsChangeEvent): void;
88 readonly onDidRegisterAuthenticationProvider: Event<AuthenticationProviderInformation>;
89 readonly onDidUnregisterAuthenticationProvider: Event<AuthenticationProviderInformation>;
90 readonly onDidChangeSessions: Event<{
91 providerId: string;
92 label: string;
93 event: AuthenticationProviderAuthenticationSessionsChangeEvent;
94 }>;
95 getSessions(providerId: string, scopes?: string[]): Promise<ReadonlyArray<AuthenticationSession>>;
96 getLabel(providerId: string): string;
97 supportsMultipleAccounts(providerId: string): boolean;
98 login(providerId: string, scopes: string[]): Promise<AuthenticationSession>;
99 logout(providerId: string, sessionId: string): Promise<void>;
100 signOutOfAccount(providerId: string, accountName: string): Promise<void>;
101}
102export interface SessionChangeEvent {
103 providerId: string;
104 label: string;
105 event: AuthenticationProviderAuthenticationSessionsChangeEvent;
106}
107export declare class AuthenticationServiceImpl implements AuthenticationService {
108 private noAccountsMenuItem;
109 private noAccountsCommand;
110 private signInRequestItems;
111 private sessionMap;
112 protected authenticationProviders: Map<string, AuthenticationProvider>;
113 private onDidRegisterAuthenticationProviderEmitter;
114 readonly onDidRegisterAuthenticationProvider: Event<AuthenticationProviderInformation>;
115 private onDidUnregisterAuthenticationProviderEmitter;
116 readonly onDidUnregisterAuthenticationProvider: Event<AuthenticationProviderInformation>;
117 private onDidChangeSessionsEmitter;
118 readonly onDidChangeSessions: Event<SessionChangeEvent>;
119 protected readonly menus: MenuModelRegistry;
120 protected readonly commands: CommandRegistry;
121 protected readonly storageService: StorageService;
122 init(): void;
123 protected handleSessionChange(changeEvent: SessionChangeEvent): Promise<void>;
124 protected createAccountUi(providerId: string, providerLabel: string, session: AuthenticationSession): DisposableCollection;
125 getProviderIds(): string[];
126 isAuthenticationProviderRegistered(id: string): boolean;
127 private updateAccountsMenuItem;
128 registerAuthenticationProvider(id: string, authenticationProvider: AuthenticationProvider): void;
129 unregisterAuthenticationProvider(id: string): void;
130 updateSessions(id: string, event: AuthenticationProviderAuthenticationSessionsChangeEvent): Promise<void>;
131 private updateNewSessionRequests;
132 requestNewSession(providerId: string, scopes: string[], extensionId: string, extensionName: string): Promise<void>;
133 getLabel(id: string): string;
134 supportsMultipleAccounts(id: string): boolean;
135 getSessions(id: string, scopes?: string[]): Promise<ReadonlyArray<AuthenticationSession>>;
136 login(id: string, scopes: string[]): Promise<AuthenticationSession>;
137 logout(id: string, sessionId: string): Promise<void>;
138 signOutOfAccount(id: string, accountName: string): Promise<void>;
139}
140export interface AllowedExtension {
141 id: string;
142 name: string;
143}
144export declare function readAllowedExtensions(storageService: StorageService, providerId: string, accountName: string): Promise<AllowedExtension[]>;
145//# sourceMappingURL=authentication-service.d.ts.map
\No newline at end of file