Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 25df016

Browse files
authored
Merge pull request #340 from topcoder-platform/feature/Auth0-RS256-Token
New auth(RS256) flow changes
2 parents 5586a3a + fc4e133 commit 25df016

File tree

12 files changed

+128
-127
lines changed

12 files changed

+128
-127
lines changed

.circleci/config.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,12 @@ workflows:
6666
context : org-global
6767
filters:
6868
branches:
69-
only:
70-
- develop
69+
only: [develop, "feature/Auth0-RS256-Token"]
7170

7271
# Production builds are exectuted only on tagged commits to the
7372
# master branch.
7473
- "build-prod":
7574
context : org-global
7675
filters:
7776
branches:
78-
only: master
77+
only: master

docker/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use the base image with Node.js
2-
FROM node:8.12
2+
FROM node:14
33

44
# Copy the current directory into the Docker image
55
COPY . /topcoder-x-ui
@@ -12,4 +12,4 @@ RUN npm install
1212
RUN npm run build
1313
#RUN npm test
1414

15-
CMD npm start
15+
CMD npm start

npm-shrinkwrap.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
"private": true,
88
"main": "src/app.js",
99
"engines": {
10-
"node": "8",
11-
"npm": "5"
10+
"node": "14",
11+
"npm": "6"
1212
},
1313
"scripts": {
14-
"start": "node src/app.js",
14+
"start": "node -r esm src/app.js",
1515
"serve": "./node_modules/.bin/concurrently \"npm run start:be\" \"npm run start:fe\"",
16-
"start:be": "nodemon src/app.js ",
16+
"start:be": "nodemon -r esm src/app.js",
1717
"start:fe": "gulp build:watch",
1818
"build": "gulp build",
1919
"test": "node ./node_modules/mocha/bin/mocha --recursive --timeout 999999 --colors tests/*.test.js --bail",
@@ -38,6 +38,7 @@
3838
"angular-ui-bootstrap": "~2.5.0",
3939
"angular-ui-router": "~1.0.23",
4040
"angularjs-datepicker": "^2.1.23",
41+
"atob": "^2.1.2",
4142
"auth0-angular": "~4.0.4",
4243
"auth0-js": "^9.11.3",
4344
"auth0-lock": "^11.17.2",
@@ -52,6 +53,7 @@
5253
"cors": "^2.8.4",
5354
"debug": "~2.6.3",
5455
"dynamoose": "^1.1.0",
56+
"esm": "^3.2.25",
5557
"express": "^4.15.4",
5658
"express-jwt": "^5.3.0",
5759
"express-session": "^1.15.5",
@@ -81,7 +83,8 @@
8183
"superagent-promise": "^1.1.0",
8284
"typescript": "~2.3.3",
8385
"uuid": "^3.3.2",
84-
"winston": "^2.3.1"
86+
"winston": "^2.3.1",
87+
"@topcoder-platform/tc-auth-lib": "git+https://github.com/topcoder-platform/tc-auth-lib.git#1.0.0"
8588
},
8689
"devDependencies": {
8790
"angular-mocks": "~1.4.4",

src/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ const express = require('express');
1515
const bodyParser = require('body-parser');
1616
const session = require('express-session');
1717
const cookieParser = require('cookie-parser');
18-
const jwtDecode = require('jwt-decode');
18+
const decodeToken = require('@topcoder-platform/tc-auth-lib').decodeToken;
1919
// const secure = require('ssl-express-www');
2020
const config = require('./config');
2121
const routes = require('./routes');
2222
const logger = require('./common/logger');
2323
const errors = require('./common/errors');
2424
const constants = require('./common/constants');
2525
const {getAppHealth} = require('./controllers/AppHealthController');
26+
global.atob = require('atob');
2627

2728
const app = express();
2829
app.use(cors());
@@ -45,7 +46,7 @@ _.forEach(routes, (verbs, path) => {
4546
actions.push((req, res, next) => {
4647
const v3jwt = _.get(req.cookies, constants.JWT_V3_NAME);
4748
if (v3jwt) {
48-
const decoded = jwtDecode(v3jwt);
49+
const decoded = decodeToken(v3jwt);
4950
req.currentUser = {
5051
handle: decoded.handle.toLowerCase(),
5152
roles: decoded.roles,

src/config.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ module.exports = {
6161
},
6262
TOPCODER_VALUES: {
6363
dev: {
64-
TC_LOGIN_URL: process.env.TC_LOGIN_URL || 'https://accounts.topcoder-dev.com/member',
64+
TC_LOGIN_URL: process.env.TC_LOGIN_URL || 'https://accounts-auth0.topcoder-dev.com',
6565
TC_USER_PROFILE_URL: process.env.TC_USER_PROFILE_URL || 'https://api.topcoder-dev.com/v2/user/profile',
6666
},
6767
prod: {
68-
TC_LOGIN_URL: process.env.TC_LOGIN_URL || 'https://accounts.topcoder.com/member',
68+
TC_LOGIN_URL: process.env.TC_LOGIN_URL || 'https://accounts-auth0.topcoder.com',
6969
TC_USER_PROFILE_URL: process.env.TC_USER_PROFILE_URL || 'https://api.topcoder.com/v2/user/profile',
7070
},
7171
},
@@ -76,11 +76,11 @@ const frontendConfigs = {
7676
"JWT_V3_NAME":"v3jwt",
7777
"JWT_V2_NAME":"tcjwt",
7878
"COOKIES_SECURE":false,
79-
"TC_LOGIN_URL": "https://accounts.topcoder-dev.com/member",
79+
"TC_LOGIN_URL": "https://accounts-auth0.topcoder-dev.com",
8080
"TC_USER_PROFILE_URL": "http://api.topcoder-dev.com/v2/user/profile",
8181
"API_URL": "https://127.0.0.1:8443",
8282
"ADMIN_TOOL_URL": "http://localhost:8080/api/v2",
83-
"ACCOUNTS_CONNECTOR_URL": "https://accounts.topcoder-dev.com/connector.html",
83+
"ACCOUNTS_CONNECTOR_URL": "https://accounts-auth0.topcoder-dev.com",
8484
"DIRECT_URL_BASE": "https://www.topcoder-dev/direct/projectOverview?formData.projectId=",
8585
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
8686
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
@@ -92,11 +92,11 @@ const frontendConfigs = {
9292
"JWT_V3_NAME":"v3jwt",
9393
"JWT_V2_NAME":"tcjwt",
9494
"COOKIES_SECURE":false,
95-
"TC_LOGIN_URL": "https://accounts.topcoder-dev.com/member",
95+
"TC_LOGIN_URL": "https://accounts-auth0.topcoder-dev.com",
9696
"TC_USER_PROFILE_URL": "https://api.topcoder-dev.com/v2/user/profile",
9797
"API_URL": "https://api.topcoder-dev.com",
9898
"ADMIN_TOOL_URL": "https://api.topcoder-dev.com/v2",
99-
"ACCOUNTS_CONNECTOR_URL": "https://accounts.topcoder-dev.com/connector.html",
99+
"ACCOUNTS_CONNECTOR_URL": "https://accounts-auth0.topcoder-dev.com",
100100
"DIRECT_URL_BASE": "https://www.topcoder-dev.com/direct/projectOverview?formData.projectId=",
101101
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
102102
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
@@ -108,11 +108,14 @@ const frontendConfigs = {
108108
"JWT_V3_NAME":"v3jwt",
109109
"JWT_V2_NAME":"tcjwt",
110110
"COOKIES_SECURE":false,
111-
"TC_LOGIN_URL": "https://accounts.topcoder-dev.com/member",
111+
"TC_LOGIN_URL": "https://accounts-auth0.topcoder-dev.com",
112+
113+
// TODO: we can clean this conf, as no need https://github.com/topcoder-platform/topcoder-x-ui/issues/342
112114
"TC_USER_PROFILE_URL": "https://api.topcoder-dev.com/v2/user/profile",
115+
113116
"API_URL": "https://api.topcoder-dev.com",
114117
"ADMIN_TOOL_URL": "https://api.topcoder-dev.com/v2",
115-
"ACCOUNTS_CONNECTOR_URL": "https://accounts.topcoder-dev.com/connector.html",
118+
"ACCOUNTS_CONNECTOR_URL": "https://accounts-auth0.topcoder-dev.com",
116119
"DIRECT_URL_BASE": "https://www.topcoder-dev.com/direct/projectOverview?formData.projectId=",
117120
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
118121
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
@@ -124,11 +127,11 @@ const frontendConfigs = {
124127
"JWT_V3_NAME":"v3jwt",
125128
"JWT_V2_NAME":"tcjwt",
126129
"COOKIES_SECURE":false,
127-
"TC_LOGIN_URL": "https://accounts.topcoder-dev.com/member",
130+
"TC_LOGIN_URL": "https://accounts-auth0.topcoder-dev.com",
128131
"TC_USER_PROFILE_URL": "https://api.topcoder-dev.com/v2/user/profile",
129132
"API_URL": "https://api.topcoder-qa.com",
130133
"ADMIN_TOOL_URL": "https://api.topcoder-qa.com/v2",
131-
"ACCOUNTS_CONNECTOR_URL": "https://accounts.topcoder-qa.com/connector.html",
134+
"ACCOUNTS_CONNECTOR_URL": "https://accounts-auth0.topcoder-dev.com",
132135
"DIRECT_URL_BASE": "https://www.topcoder-dev.com/direct/projectOverview?formData.projectId=",
133136
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
134137
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
@@ -140,11 +143,11 @@ const frontendConfigs = {
140143
"JWT_V3_NAME":"v3jwt",
141144
"JWT_V2_NAME":"tcjwt",
142145
"COOKIES_SECURE":false,
143-
"TC_LOGIN_URL": "https://accounts.topcoder.com/member",
146+
"TC_LOGIN_URL": "https://accounts-auth0.topcoder.com",
144147
"TC_USER_PROFILE_URL": "https://api.topcoder.com/v2/user/profile",
145148
"API_URL": "https://api.topcoder.com",
146149
"ADMIN_TOOL_URL": "https://api.topcoder.com/v2",
147-
"ACCOUNTS_CONNECTOR_URL": "https://accounts.topcoder.com/connector.html",
150+
"ACCOUNTS_CONNECTOR_URL": "https://accounts-auth0.topcoder.com",
148151
"DIRECT_URL_BASE": "https://www.topcoder.com/direct/projectOverview?formData.projectId=",
149152
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
150153
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
@@ -173,4 +176,4 @@ module.exports.frontendConfigs = {
173176
TOPCODER_URL: process.env.TOPCODER_URL || frontendConfigs[activeEnv].TOPCODER_URL,
174177
GITHUB_TEAM_URL: process.env.GITHUB_TEAM_URL || frontendConfigs[activeEnv].GITHUB_TEAM_URL,
175178
GITLAB_GROUP_URL: process.env.GITLAB_GROUP_URL || frontendConfigs[activeEnv].GITLAB_GROUP_URL
176-
};
179+
};

src/front/src/app/auth/auth.config.js

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,6 @@
99

1010
angular.module('topcoderX')
1111
.config(['$httpProvider', 'jwtInterceptorProvider', function ($httpProvider, jwtInterceptorProvider) {
12-
var refreshingToken = null;
13-
14-
function handleRefreshResponse(res, $authService) {
15-
var ref;
16-
var ref1;
17-
var ref2;
18-
19-
const newToken = (ref = res.data) != null ? (ref1 = ref.result) != null ?
20-
(ref2 = ref1.content) != null ? ref2.token : void 0 : void 0 : void 0;
21-
22-
$authService.setTokenV3(newToken);
23-
24-
return newToken;
25-
};
26-
27-
function refreshingTokenComplete() {
28-
refreshingToken = null;
29-
};
30-
3112
jwtInterceptorProvider.tokenGetter = [
3213
'AuthService', '$http', 'Helper', '$rootScope', 'config',
3314
function (AuthService, $http, Helper, $rootScope, config) {
@@ -43,18 +24,9 @@ angular.module('topcoderX')
4324
var currentToken = AuthService.getTokenV3();
4425

4526
if (AuthService.getTokenV3() && AuthService.isTokenV3Expired()) {
46-
if (refreshingToken === null) {
47-
refreshingToken = $http({
48-
method: 'GET',
49-
url: $rootScope.appConfig.API_URL + "/v3/authorizations/1",
50-
headers: {
51-
'Authorization': "Bearer " + currentToken
52-
}
53-
}).then(function (res) { handleRefreshResponse(res, AuthService) })["finally"](refreshingTokenComplete).catch(function () {
54-
AuthService.login();
55-
});
56-
}
57-
return refreshingToken;
27+
var token = AuthService.getToken('v3jwt')
28+
if (token) return token
29+
else AuthService.login()
5830
} else {
5931
return currentToken;
6032
}

0 commit comments

Comments
 (0)