@@ -10,6 +10,7 @@ import { GitpodPublicApi, IGitpodAPI } from '../publicApi';
10
10
import { eventToPromise } from '../common/event' ;
11
11
import { ILogService } from './logService' ;
12
12
import { ITelemetryService } from '../common/telemetry' ;
13
+ import { arrayEquals } from '../common/utils' ;
13
14
14
15
export class NoSignedInError extends Error {
15
16
constructor ( ) {
@@ -31,7 +32,16 @@ export interface ISessionService {
31
32
didFirstLoad : Promise < void > ;
32
33
}
33
34
34
- const sessionScopes = [
35
+ const defaultSessionScopes = [
36
+ 'function:getWorkspace' ,
37
+ 'function:getOwnerToken' ,
38
+ 'function:getLoggedInUser' ,
39
+ 'function:getSSHPublicKeys' ,
40
+ 'function:sendHeartBeat' ,
41
+ 'resource:default'
42
+ ] ;
43
+
44
+ const managementSessionScopes = [
35
45
'function:getWorkspaces' ,
36
46
'function:getWorkspace' ,
37
47
'function:startWorkspace' ,
@@ -67,8 +77,8 @@ export class SessionService extends Disposable implements ISessionService {
67
77
super ( ) ;
68
78
69
79
this . _register ( vscode . authentication . onDidChangeSessions ( e => this . handleOnDidChangeSessions ( e ) ) ) ;
70
- this . firstLoadPromise = this . tryLoadSession ( false ) ;
71
- this . firstLoadPromise . then ( ( ) => vscode . commands . executeCommand ( 'setContext' , 'gitpod.authenticated' , this . isSignedIn ( ) ) ) ;
80
+ this . firstLoadPromise = this . tryLoadSession ( false , managementSessionScopes ) . then ( ( ) => this . tryLoadSession ( false , defaultSessionScopes ) /* delete this after some time when users have a session with managementSessionScopes */ ) ;
81
+ this . firstLoadPromise . then ( ( ) => vscode . commands . executeCommand ( 'setContext' , 'gitpod.authenticated' , this . session && arrayEquals ( this . session . scopes . slice ( 0 ) . sort ( ) , managementSessionScopes . slice ( ) . sort ( ) ) ) ) ;
72
82
}
73
83
74
84
private async handleOnDidChangeSessions ( e : vscode . AuthenticationSessionsChangeEvent ) {
@@ -77,8 +87,9 @@ export class SessionService extends Disposable implements ISessionService {
77
87
}
78
88
const oldSession = this . session ;
79
89
this . session = undefined as vscode . AuthenticationSession | undefined ;
80
- await this . tryLoadSession ( false ) ;
81
- vscode . commands . executeCommand ( 'setContext' , 'gitpod.authenticated' , this . isSignedIn ( ) ) ;
90
+ await this . tryLoadSession ( false , managementSessionScopes ) ;
91
+ await this . tryLoadSession ( false , defaultSessionScopes ) ; // delete this after some time when users have a session with managementSessionScopes
92
+ vscode . commands . executeCommand ( 'setContext' , 'gitpod.authenticated' , this . session && arrayEquals ( this . session . scopes . slice ( 0 ) . sort ( ) , managementSessionScopes . slice ( ) . sort ( ) ) ) ;
82
93
// host changed, sign out, sign in
83
94
const didChange = oldSession ?. id !== this . session ?. id ;
84
95
if ( didChange ) {
@@ -92,19 +103,19 @@ export class SessionService extends Disposable implements ISessionService {
92
103
return ! ! this . session ;
93
104
}
94
105
95
- async signIn ( gitpodHost ?: string ) {
106
+ async signIn ( gitpodHost ?: string , scopes : string [ ] = managementSessionScopes ) {
96
107
if ( this . loginPromise ) {
97
108
this . logger . info ( `Existing login in progress. Waiting for completion...` ) ;
98
109
return this . loginPromise ;
99
110
}
100
111
101
- this . loginPromise = this . doSignIn ( gitpodHost ) ;
112
+ this . loginPromise = this . doSignIn ( gitpodHost || this . hostService . gitpodHost , scopes ) ;
102
113
this . loginPromise . finally ( ( ) => this . loginPromise = undefined ) ;
103
114
return this . loginPromise ;
104
115
}
105
116
106
- private async doSignIn ( gitpodHost ? : string ) {
107
- if ( gitpodHost && new URL ( this . hostService . gitpodHost ) . host !== new URL ( gitpodHost ) . host ) {
117
+ private async doSignIn ( gitpodHost : string , scopes : string [ ] ) {
118
+ if ( new URL ( this . hostService . gitpodHost ) . host !== new URL ( gitpodHost ) . host ) {
108
119
const changedSessionPromise = eventToPromise ( this . onDidChangeSession ) ;
109
120
const updated = await this . hostService . changeHost ( gitpodHost ) ;
110
121
if ( ! updated ) {
@@ -114,11 +125,11 @@ export class SessionService extends Disposable implements ISessionService {
114
125
await changedSessionPromise ;
115
126
}
116
127
117
- if ( this . isSignedIn ( ) ) {
128
+ if ( this . session && arrayEquals ( this . session . scopes . slice ( 0 ) . sort ( ) , scopes . slice ( ) . sort ( ) ) ) {
118
129
return ;
119
130
}
120
131
121
- await this . tryLoadSession ( true ) ;
132
+ await this . tryLoadSession ( true , scopes ) ;
122
133
123
134
if ( this . isSignedIn ( ) ) {
124
135
this . logger . info ( `Successfully signed in` ) ;
@@ -127,15 +138,15 @@ export class SessionService extends Disposable implements ISessionService {
127
138
}
128
139
}
129
140
130
- private async tryLoadSession ( force : boolean ) {
141
+ private async tryLoadSession ( force : boolean , scopes : string [ ] ) {
131
142
try {
132
143
if ( this . session && ! force ) {
133
144
return ;
134
145
}
135
146
136
147
this . session = await vscode . authentication . getSession (
137
148
'gitpod' ,
138
- sessionScopes ,
149
+ scopes ,
139
150
{
140
151
createIfNone : force ,
141
152
silent : ! force ,
0 commit comments