Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit 7c92998

Browse files
committed
https://trello.com/c/5vWCb7UG - add notifications scope for github cr2pr
1 parent 178743b commit 7c92998

5 files changed

Lines changed: 50 additions & 71 deletions

File tree

api_server/lib/oauth/oauth_module.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,10 @@ class OAuthModule extends APIServerModule {
462462
hasIssues: hasIssues,
463463
hasSharing: hasSharing
464464
};
465-
if (forEnterprise && scopes) {
466-
info.scopes = scopes.split(',');
465+
if (scopes) {
466+
const scopes_comma = scopes.split(',');
467+
const scopes_space = scopes.split(' ');
468+
info.scopes = scopes_comma.length > scopes_space.length ? scopes_comma : scopes_space;
467469
}
468470
return info;
469471
}

api_server/modules/github_auth/github_auth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const OAUTH_CONFIG = {
1212
authPath: 'login/oauth/authorize',
1313
tokenPath: 'login/oauth/access_token',
1414
exchangeFormat: 'query',
15-
scopes: 'repo,read:user,user:email',
15+
scopes: 'repo,read:user,user:email,notifications',
1616
noGrantType: true,
1717
hasIssues: true,
1818
supportsSignup: true

api_server/modules/providers/provider_test_constants.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const STANDARD_PROVIDER_HOSTS = {
1717
isEnterprise: false,
1818
host: 'bitbucket.org',
1919
apiHost: 'api.bitbucket.org/2.0',
20-
hasIssues: true
20+
hasIssues: true,
21+
scopes: ['account', 'team', 'repository', 'issue:write', 'pullrequest:write']
2122
},
2223
'bitbucket/server': {
2324
id: 'bitbucket/server',
@@ -26,15 +27,16 @@ const STANDARD_PROVIDER_HOSTS = {
2627
forEnterprise: true,
2728
host: 'bitbucket/server',
2829
apiHost: 'api.bitbucket.org/2.0',
29-
scopes: ['projects:read repositories:write']
30+
scopes: ['projects:read', 'repositories:write']
3031
},
3132
'github*com': {
3233
id: 'github*com',
3334
name: 'github',
3435
isEnterprise: false,
3536
host: 'github.com',
3637
apiHost: 'api.github.com',
37-
hasIssues: true
38+
hasIssues: true,
39+
scopes: ['repo', 'read:user', 'user:email', 'notifications']
3840
},
3941
'github/enterprise': {
4042
id: 'github/enterprise',
@@ -51,7 +53,8 @@ const STANDARD_PROVIDER_HOSTS = {
5153
isEnterprise: false,
5254
host: 'gitlab.com',
5355
apiHost: 'gitlab.com/api/v4',
54-
hasIssues: true
56+
hasIssues: true,
57+
5558
},
5659
'gitlab/enterprise': {
5760
id: 'gitlab/enterprise',
@@ -69,7 +72,8 @@ const STANDARD_PROVIDER_HOSTS = {
6972
isEnterprise: false,
7073
host: 'auth.atlassian.com',
7174
apiHost: 'api.atlassian.com',
72-
hasIssues: true
75+
hasIssues: true,
76+
scopes: ['read:jira-user', 'read:jira-work', 'write:jira-work', 'offline_access']
7377
},
7478
'jiraserver/enterprise': {
7579
id: 'jiraserver/enterprise',
@@ -86,15 +90,17 @@ const STANDARD_PROVIDER_HOSTS = {
8690
isEnterprise: false,
8791
host: 'trello.com',
8892
apiHost: 'api.trello.com/1',
89-
hasIssues: true
93+
hasIssues: true,
94+
scopes: ['read', 'write']
9095
},
9196
'youtrack*com': {
9297
id: 'youtrack*com',
9398
name: 'youtrack',
9499
isEnterprise: false,
95100
needsConfigure: true,
96101
host: 'youtrack.com',
97-
hasIssues: true
102+
hasIssues: true,
103+
scopes: ['YouTrack']
98104
},
99105
'app*vssps*visualstudio*com': {
100106
id: 'app*vssps*visualstudio*com',
@@ -103,23 +109,39 @@ const STANDARD_PROVIDER_HOSTS = {
103109
needsConfigure: true,
104110
host: 'app.vssps.visualstudio.com',
105111
apiHost: 'dev.azure.com',
106-
hasIssues: true
112+
hasIssues: true,
113+
scopes: ['vso.identity', 'vso.work_write']
107114
},
108115
'slack*com': {
109116
id: 'slack*com',
110117
name: 'slack',
111118
isEnterprise: false,
112119
host: 'slack.com',
113120
apiHost: 'slack.com/api',
114-
hasSharing: true
121+
hasSharing: true,
122+
scopes: [
123+
'channels:read',
124+
'chat:write:user',
125+
'groups:read',
126+
'im:read',
127+
'users.profile:write',
128+
'users:read',
129+
'users:read.email',
130+
'mpim:read'
131+
]
115132
},
116133
'login*microsoftonline*com': {
117134
id: 'login*microsoftonline*com',
118135
name: 'msteams',
119136
isEnterprise: false,
120137
host: 'login.microsoftonline.com',
121138
apiHost: 'graph.microsoft.com/v1.0',
122-
hasSharing: true
139+
hasSharing: true,
140+
scopes: [
141+
'User.Read.All',
142+
'Group.ReadWrite.All',
143+
'offline_access'
144+
]
123145
}
124146
/*
125147
'okta*com': {

api_server/modules/providers/test/provider_auth/provider_auth_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class ProviderAuthTest extends CodeStreamAPITest {
170170
redirect_uri: this.redirectUri,
171171
response_type: 'code',
172172
state: this.state,
173-
scope: 'repo,read:user,user:email'
173+
scope: 'repo,read:user,user:email,notifications'
174174
};
175175
const host = this.testHost || 'https://github.com';
176176
const url = `${host}/login/oauth/authorize`;

api_server/modules/slack_auth/slack_auth.js

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,6 @@ const Fetch = require('node-fetch');
66
const OAuthModule = require(process.env.CSSVC_BACKEND_ROOT + '/api_server/lib/oauth/oauth_module.js');
77
const SlackAuthorizer = require('./slack_authorizer');
88

9-
const OAUTH_CONFIG = {
10-
provider: 'slack',
11-
host: 'slack.com',
12-
apiHost: 'slack.com/api',
13-
authPath: 'oauth/authorize',
14-
tokenPath: 'api/oauth.access',
15-
exchangeFormat: 'form',
16-
scopes: 'identify client',
17-
hasSharing: true
18-
};
19-
20-
const STRICT_SCOPES = [
21-
'channels:history',
22-
'channels:read',
23-
'channels:write',
24-
'chat:write:user',
25-
'groups:history',
26-
'groups:read',
27-
'groups:write',
28-
'im:history',
29-
'im:read',
30-
'im:write',
31-
'users:read',
32-
'users:read.email',
33-
'users.profile:read',
34-
'reactions:write',
35-
'mpim:history',
36-
'mpim:read',
37-
'mpim:write'
38-
];
39-
409
const SHARING_SCOPES = [
4110
'channels:read',
4211
'chat:write:user',
@@ -48,6 +17,18 @@ const SHARING_SCOPES = [
4817
'mpim:read'
4918
];
5019

20+
const OAUTH_CONFIG = {
21+
provider: 'slack',
22+
host: 'slack.com',
23+
apiHost: 'slack.com/api',
24+
authPath: 'oauth/authorize',
25+
tokenPath: 'api/oauth.access',
26+
exchangeFormat: 'form',
27+
scopes: SHARING_SCOPES.join(' '),
28+
hasSharing: true
29+
};
30+
31+
5132
class SlackAuth extends OAuthModule {
5233
constructor (config) {
5334
super(config);
@@ -61,32 +42,6 @@ class SlackAuth extends OAuthModule {
6142
}).exchangeAndAuthorize();
6243
}
6344

64-
// overrides OAuthModule.getRedirectData to allow for "slack-lite", slack without the
65-
// scary "client" scope
66-
getRedirectData (options) {
67-
const data = super.getRedirectData(options);
68-
if (options.access === 'strict') {
69-
data.parameters.scope = STRICT_SCOPES.join(' ');
70-
} else if (options.sharing) {
71-
data.parameters.scope = SHARING_SCOPES.join(' ');
72-
}
73-
return data;
74-
}
75-
76-
// overrides OAuthModule.getClientInfo to allow for "slack-lite", slack without the
77-
// scary "client" scope ... in this case, we use different client ID and secret
78-
getClientInfo (options) {
79-
const info = super.getClientInfo(options);
80-
if (options.access === 'strict') {
81-
info.clientId = this.apiConfig.appStrictClientId;
82-
info.clientSecret = this.apiConfig.appStrictClientSecret;
83-
} else if (options.sharing) {
84-
info.clientId = this.apiConfig.appSharingClientId;
85-
info.clientSecret = this.apiConfig.appSharingClientSecret;
86-
}
87-
return info;
88-
}
89-
9045
validateChannelName (name) {
9146
if (name.match(/[^a-z0-9-_[\]{}\\/]/)) {
9247
return 'illegal characters in channel name';

0 commit comments

Comments
 (0)