Skip to content

Master : new auth changes - 29 Oct 2020 #890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config/constants/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const DOMAIN = 'topcoder-dev.com'
const DEV_API_HOSTNAME = `https://api.${DOMAIN}`

module.exports = {
ACCOUNTS_APP_CONNECTOR_URL: `https://accounts.${DOMAIN}/connector.html`,
ACCOUNTS_APP_LOGIN_URL: `https://accounts.${DOMAIN}/member`,
ACCOUNTS_APP_CONNECTOR_URL: `https://accounts-auth0.${DOMAIN}`,
ACCOUNTS_APP_LOGIN_URL: `https://accounts-auth0.${DOMAIN}`,
COMMUNITY_APP_URL: `https://www.${DOMAIN}`,
MEMBER_API_URL: `${DEV_API_HOSTNAME}/v4/members`,
MEMBER_API_V3_URL: `${DEV_API_HOSTNAME}/v3/members`,
Expand All @@ -24,7 +24,7 @@ module.exports = {
CONNECT_APP_URL: `https://connect.${DOMAIN}`,
DIRECT_PROJECT_URL: `https://www.${DOMAIN}/direct`,
ONLINE_REVIEW_URL: `https://software.${DOMAIN}`,
DEFAULT_TERM_UUID: 'b11da5cd-713f-478d-90f4-f679ef53ee95', // Terms & Conditions of Use at TopCoder
DEFAULT_TERM_UUID: '64d6e249-d7a5-4591-8ff5-e872f8a051f9', // Terms & Conditions of Use at TopCoder
DEFAULT_NDA_UUID: '77f558c1-56fb-427c-b974-61ea0a060ca7', // Appirio NDA v2.0
SUBMITTER_ROLE_UUID: '732339e7-8e30-49d7-9198-cccf9451e221',
DEV_TRACK_ID: '9b6fc876-f4d9-4ccb-9dfd-419247628825',
Expand Down
4 changes: 2 additions & 2 deletions config/constants/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const DOMAIN = 'topcoder.com'
const PROD_API_HOSTNAME = `https://api.${DOMAIN}`

module.exports = {
ACCOUNTS_APP_CONNECTOR_URL: process.env.ACCOUNTS_APP_CONNECTOR_URL || `https://accounts.${DOMAIN}/connector.html`,
ACCOUNTS_APP_LOGIN_URL: `https://accounts.${DOMAIN}/member`,
ACCOUNTS_APP_CONNECTOR_URL: process.env.ACCOUNTS_APP_CONNECTOR_URL || `https://accounts-auth0.${DOMAIN}`,
ACCOUNTS_APP_LOGIN_URL: `https://accounts-auth0.${DOMAIN}`,
COMMUNITY_APP_URL: `https://www.${DOMAIN}`,
MEMBER_API_URL: `${PROD_API_HOSTNAME}/v4/members`,
MEMBER_API_V3_URL: `${PROD_API_HOSTNAME}/v3/members`,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"sass-loader": "7.1.0",
"simplemde": "^1.11.2",
"style-loader": "0.23.0",
"tc-accounts": "git+https://github.com/appirio-tech/accounts-app.git",
"tc-auth-lib": "topcoder-platform/tc-auth-lib#1.0.1",
"terser": "^3.16.1",
"terser-webpack-plugin": "1.1.0",
"topcoder-healthcheck-dropin": "^1.0.3",
Expand Down
2 changes: 1 addition & 1 deletion src/actions/auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { configureConnector, decodeToken } from 'tc-accounts'
import { configureConnector, decodeToken } from 'tc-auth-lib'
import { fetchProfile } from '../services/user'
import {
LOAD_USER_SUCCESS,
Expand Down
5 changes: 2 additions & 3 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Redirect, Route, Switch, withRouter } from 'react-router-dom'
import jwtDecode from 'jwt-decode'
import _ from 'lodash'
import renderApp from './components/App'
import TopBarContainer from './containers/TopbarContainer'
import Sidebar from './containers/Sidebar'
import ChallengeList from './containers/Challenges'
import ChallengeEditor from './containers/ChallengeEditor'
import { getFreshToken } from 'tc-accounts'
import { getFreshToken, decodeToken } from 'tc-auth-lib'
import { saveToken } from './actions/auth'
import { loadChallengeDetails } from './actions/challenges'
import { connect } from 'react-redux'
Expand Down Expand Up @@ -78,7 +77,7 @@ class Routes extends React.Component {
return null
}

let isAllowed = checkAllowedRoles(_.get(jwtDecode(this.props.token), 'roles'))
let isAllowed = checkAllowedRoles(_.get(decodeToken(this.props.token), 'roles'))

if (!isAllowed) {
let warnMessage = 'You are not authorized to use this application'
Expand Down
2 changes: 1 addition & 1 deletion src/services/axiosWithAuth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios'
import store from '../config/store'
import { getFreshToken, isTokenExpired } from 'tc-accounts'
import { getFreshToken, isTokenExpired } from 'tc-auth-lib'
const { ACCOUNTS_APP_LOGIN_URL } = process.env

/**
Expand Down
4 changes: 2 additions & 2 deletions src/util/tc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { MARATHON_MATCH_SUBTRACKS, CHALLENGE_TRACKS, ALLOWED_USER_ROLES, ADMIN_ROLES } from '../config/constants'
import _ from 'lodash'
import jwtDecode from 'jwt-decode'
import { decodeToken } from 'tc-auth-lib'

export const RATING_COLORS = [{
color: '#9D9FA0' /* Grey */,
Expand Down Expand Up @@ -56,6 +56,6 @@ export const checkAllowedRoles = (roles) => roles.some(val => ALLOWED_USER_ROLES
* @param token
*/
export const checkAdmin = (token) => {
const roles = _.get(jwtDecode(token), 'roles')
const roles = _.get(decodeToken(token), 'roles')
return roles.some(val => ADMIN_ROLES.indexOf(val.toLowerCase()) > -1)
}