6
6
7
7
import { AuthProviderType } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb" ;
8
8
9
- export namespace GitLabScope {
9
+ export namespace GitLabOAuthScopes {
10
10
export const READ_USER = "read_user" ;
11
11
export const API = "api" ;
12
12
export const READ_REPO = "read_repository" ;
13
13
14
14
export const ALL = [ READ_USER , API , READ_REPO ] ;
15
- /**
16
- * Minimal required permission.
17
- * GitLab API usage requires the permission of a user.
18
- */
19
- export const DEFAULT = [ READ_USER , API ] ;
20
- export const REPO = [ API , READ_REPO ] ;
15
+
16
+ export const Requirements = {
17
+ /**
18
+ * Minimal required permission.
19
+ * GitLab API usage requires the permission of a user.
20
+ */
21
+ DEFAULT : [ READ_USER , API ] ,
22
+
23
+ REPO : [ API , READ_REPO ] ,
24
+ } ;
21
25
}
22
26
23
- export namespace GitHubScope {
27
+ export namespace GitHubOAuthScopes {
24
28
export const EMAIL = "user:email" ;
25
29
export const READ_USER = "read:user" ;
26
30
export const PUBLIC = "public_repo" ;
@@ -29,9 +33,17 @@ export namespace GitHubScope {
29
33
export const WORKFLOW = "workflow" ;
30
34
31
35
export const ALL = [ EMAIL , READ_USER , PUBLIC , PRIVATE , ORGS , WORKFLOW ] ;
32
- export const DEFAULT = ALL ;
33
- export const PUBLIC_REPO = ALL ;
34
- export const PRIVATE_REPO = ALL ;
36
+
37
+ export const Requirements = {
38
+ /**
39
+ * Minimal required permission.
40
+ * GitHub's API is not restricted any further.
41
+ */
42
+ DEFAULT : [ EMAIL ] ,
43
+
44
+ PUBLIC_REPO : [ PUBLIC ] ,
45
+ PRIVATE_REPO : [ PRIVATE ] ,
46
+ } ;
35
47
}
36
48
37
49
export namespace BitbucketOAuthScopes {
@@ -48,15 +60,14 @@ export namespace BitbucketOAuthScopes {
48
60
/** Create, comment and merge pull requests */
49
61
export const PULL_REQUEST_WRITE = "pullrequest:write" ;
50
62
51
- export const ALL = [
52
- ACCOUNT_READ ,
53
- REPOSITORY_READ ,
54
- REPOSITORY_WRITE ,
55
- PULL_REQUEST_READ ,
56
- PULL_REQUEST_WRITE ,
57
- ] ;
63
+ export const ALL = [ ACCOUNT_READ , REPOSITORY_READ , REPOSITORY_WRITE , PULL_REQUEST_READ , PULL_REQUEST_WRITE ] ;
58
64
59
- export const DEFAULT = ALL ;
65
+ export const Requirements = {
66
+ /**
67
+ * Minimal required permission.
68
+ */
69
+ DEFAULT : ALL ,
70
+ } ;
60
71
}
61
72
62
73
export namespace BitbucketServerOAuthScopes {
@@ -74,17 +85,22 @@ export namespace BitbucketServerOAuthScopes {
74
85
75
86
export const ALL = [ PUBLIC_REPOS , REPO_READ , REPO_WRITE , REPO_ADMIN , PROJECT_ADMIN ] ;
76
87
77
- export const DEFAULT = ALL ;
88
+ export const Requirements = {
89
+ /**
90
+ * Minimal required permission.
91
+ */
92
+ DEFAULT : [ PUBLIC_REPOS , REPO_READ , REPO_WRITE ] ,
93
+ } ;
78
94
}
79
95
80
96
export function getScopesForAuthProviderType ( type : AuthProviderType | string ) {
81
97
switch ( type ) {
82
98
case AuthProviderType . GITHUB :
83
99
case "GitHub" :
84
- return GitHubScope . ALL ;
100
+ return GitHubOAuthScopes . ALL ;
85
101
case AuthProviderType . GITLAB :
86
102
case "GitLab" :
87
- return GitLabScope . ALL ;
103
+ return GitLabOAuthScopes . ALL ;
88
104
case AuthProviderType . BITBUCKET :
89
105
case "Bitbucket" :
90
106
return BitbucketOAuthScopes . ALL ;
@@ -99,30 +115,30 @@ export function getRequiredScopes(type: AuthProviderType | string) {
99
115
case AuthProviderType . GITHUB :
100
116
case "GitHub" :
101
117
return {
102
- default : GitHubScope . DEFAULT ,
103
- publicRepo : GitHubScope . PUBLIC_REPO ,
104
- privateRepo : GitHubScope . PRIVATE_REPO ,
118
+ default : GitHubOAuthScopes . Requirements . DEFAULT ,
119
+ publicRepo : GitHubOAuthScopes . Requirements . PUBLIC_REPO ,
120
+ privateRepo : GitHubOAuthScopes . Requirements . PRIVATE_REPO ,
105
121
} ;
106
122
case AuthProviderType . GITLAB :
107
123
case "GitLab" :
108
124
return {
109
- default : GitLabScope . DEFAULT ,
110
- publicRepo : GitLabScope . DEFAULT ,
111
- privateRepo : GitLabScope . REPO ,
125
+ default : GitLabOAuthScopes . Requirements . DEFAULT ,
126
+ publicRepo : GitLabOAuthScopes . Requirements . DEFAULT ,
127
+ privateRepo : GitLabOAuthScopes . Requirements . REPO ,
112
128
} ;
113
129
case AuthProviderType . BITBUCKET :
114
130
case "Bitbucket" :
115
131
return {
116
- default : BitbucketOAuthScopes . DEFAULT ,
117
- publicRepo : BitbucketOAuthScopes . DEFAULT ,
118
- privateRepo : BitbucketOAuthScopes . DEFAULT ,
132
+ default : BitbucketOAuthScopes . Requirements . DEFAULT ,
133
+ publicRepo : BitbucketOAuthScopes . Requirements . DEFAULT ,
134
+ privateRepo : BitbucketOAuthScopes . Requirements . DEFAULT ,
119
135
} ;
120
136
case AuthProviderType . BITBUCKET_SERVER :
121
137
case "BitbucketServer" :
122
138
return {
123
- default : BitbucketServerOAuthScopes . DEFAULT ,
124
- publicRepo : BitbucketServerOAuthScopes . DEFAULT ,
125
- privateRepo : BitbucketServerOAuthScopes . DEFAULT ,
139
+ default : BitbucketServerOAuthScopes . Requirements . DEFAULT ,
140
+ publicRepo : BitbucketServerOAuthScopes . Requirements . DEFAULT ,
141
+ privateRepo : BitbucketServerOAuthScopes . Requirements . DEFAULT ,
126
142
} ;
127
143
}
128
144
}
0 commit comments