From b26486a72a29b160399fc68eee33999cd035b168 Mon Sep 17 00:00:00 2001 From: Pierce Trey Date: Wed, 5 May 2021 15:38:42 -0600 Subject: [PATCH 1/4] remove auth flow - ui will be for external users or behind internal google oauth --- src/App.js | 26 ++-------------- src/AppContainer.tsx | 6 +--- src/interceptors/401-interceptor.ts | 22 -------------- src/interceptors/index.ts | 2 -- src/interceptors/jwt-interceptor.ts | 47 ----------------------------- src/reducers/identity-reducer.ts | 37 ----------------------- src/reducers/index.ts | 2 -- src/store/index.js | 3 -- 8 files changed, 3 insertions(+), 142 deletions(-) delete mode 100644 src/interceptors/401-interceptor.ts delete mode 100644 src/interceptors/index.ts delete mode 100644 src/interceptors/jwt-interceptor.ts delete mode 100644 src/reducers/identity-reducer.ts diff --git a/src/App.js b/src/App.js index 6f29b53..ad9b7a9 100644 --- a/src/App.js +++ b/src/App.js @@ -1,35 +1,13 @@ -import React, { useEffect } from 'react'; +import React from 'react'; import { Switch, Route, Redirect } from 'react-router-dom'; import DashboardContainer from 'components/Dashboard/DashboardContainer'; import { ContractContainer, ContractListContainer } from 'components/Contract'; -import { LoginContainer } from 'components/Login'; import { KeyManagerContainer, AddServiceKeyModal } from 'components/KeyManagement'; -import { OAuthCallback } from 'components/OAuth'; import KeyDetailsContainer from 'components/KeyManagement/KeyDetailsContainer'; import { ScopeContainer, ScopeHistoryContainer, ScopeListContainer } from 'components/Scopes'; import { Settings } from 'Constant'; -import { useDeepLink } from 'hooks'; - -const App = ({ isAuthenticated }) => { - const { performDeepLink } = useDeepLink(); - - useEffect(() => { - if (isAuthenticated) { - performDeepLink(); - } - }, [isAuthenticated, performDeepLink]); - - if (!isAuthenticated) { - return ( - <> - - - - - - ); - } +const App = () => { return ( <> diff --git a/src/AppContainer.tsx b/src/AppContainer.tsx index 7c72b66..790d164 100644 --- a/src/AppContainer.tsx +++ b/src/AppContainer.tsx @@ -1,14 +1,10 @@ import React from 'react'; -import { useSelector } from 'react-redux'; import App from 'App'; import { ErrorCardContainer } from 'components/ErrorCards'; export const AppContainer = () => { - const { jwt } = useSelector(({ identityReducer }) => identityReducer); - const isAuthenticated = typeof jwt === 'string' && jwt.length > 0; - return (<> - + ); } \ No newline at end of file diff --git a/src/interceptors/401-interceptor.ts b/src/interceptors/401-interceptor.ts deleted file mode 100644 index 60728fc..0000000 --- a/src/interceptors/401-interceptor.ts +++ /dev/null @@ -1,22 +0,0 @@ -import store from 'store'; -import { logout } from 'actions/identity-actions'; -import { addError, ErrorLevels } from 'actions/error-actions'; -import debounce from 'lodash.debounce'; -import { axios } from 'actions'; - -const handle401 = debounce(() => { - store.dispatch(addError('Unauthenticated, please log in again', ErrorLevels.WARNING)); - store.dispatch(logout()); -}, 1000) - -export const setup401Interceptor = () => { - axios.interceptors.response.use(response => response, - error => { - const response = error.response; - if (response?.status === 401) { - handle401(); - } - - throw error; - }) -} \ No newline at end of file diff --git a/src/interceptors/index.ts b/src/interceptors/index.ts deleted file mode 100644 index 7aecccc..0000000 --- a/src/interceptors/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { setupJwtInterceptor } from './jwt-interceptor'; -export { setup401Interceptor } from './401-interceptor'; \ No newline at end of file diff --git a/src/interceptors/jwt-interceptor.ts b/src/interceptors/jwt-interceptor.ts deleted file mode 100644 index e475fea..0000000 --- a/src/interceptors/jwt-interceptor.ts +++ /dev/null @@ -1,47 +0,0 @@ -import store from 'store'; -import { jwtStorageKey } from 'reducers/identity-reducer'; -import { logout, login } from 'actions/identity-actions'; -import { axios } from 'actions'; - -const storeJwt = (): string | null => store.getState()?.identityReducer?.jwt; - -const getInterceptor = (jwt?: string) => config => { - config = { - ...config, - headers: { - ...config.headers, - Authorization: `Bearer ${jwt}` - } - } - - return config; -}; - -let interceptor; -export const setupJwtInterceptor = (jwt: string = '') => { - if (interceptor !== undefined) { - axios.interceptors.request.eject(interceptor); - } - - interceptor = axios.interceptors.request.use(getInterceptor(jwt)); -} - -axios.interceptors.response.use(response => { - if (response?.headers?.authorization) { - store.dispatch(login(response.headers.authorization)) - } - return response; -}) - -window.addEventListener('storage', (e) => { - if (!e.key || e.key === jwtStorageKey) { - const exitingJwt = storeJwt(); - const newJwt = window.localStorage.getItem(jwtStorageKey); - - if (exitingJwt && !newJwt) { - store.dispatch(logout()); - } else if (newJwt && exitingJwt !== newJwt) { - store.dispatch(login(newJwt)); - } - } -}) \ No newline at end of file diff --git a/src/reducers/identity-reducer.ts b/src/reducers/identity-reducer.ts deleted file mode 100644 index bcff56b..0000000 --- a/src/reducers/identity-reducer.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { handleActions } from "redux-actions" -import { LOGOUT, LOGIN } from "actions/identity-actions"; -import { setupJwtInterceptor } from "interceptors"; - -export const jwtStorageKey = 'jwt'; - -const initialState = (() => { - const storedJwt = window.localStorage.getItem(jwtStorageKey); - setupJwtInterceptor(storedJwt || ''); - - return { - jwt: storedJwt || '', - }; -})(); - -const identityReducer = handleActions({ - [LOGOUT]: (state, action) => { - window.localStorage.setItem(jwtStorageKey, ''); - setupJwtInterceptor(); - - return { - ...state, - jwt: '' - } - }, - [LOGIN]: (state, { payload: jwt }) => { - window.localStorage.setItem(jwtStorageKey, jwt); - setupJwtInterceptor(jwt); - - return { - ...state, - jwt - } - } -}, initialState); - -export default identityReducer; \ No newline at end of file diff --git a/src/reducers/index.ts b/src/reducers/index.ts index 69d3b9b..198d08f 100644 --- a/src/reducers/index.ts +++ b/src/reducers/index.ts @@ -2,7 +2,6 @@ import { default as contractReducer } from './contract-reducer'; import { default as scopeReducer } from './scope-reducer'; import { default as objectReducer } from './object-reducer'; import { default as keyReducer } from './key-reducer'; -import { default as identityReducer } from './identity-reducer'; import { default as errorReducer } from './error-reducer'; export default { @@ -10,6 +9,5 @@ export default { scopeReducer, objectReducer, keyReducer, - identityReducer, errorReducer, }; diff --git a/src/store/index.js b/src/store/index.js index 71bbc69..c9660c1 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,7 +1,6 @@ import { applyMiddleware, createStore, combineReducers, compose } from 'redux'; import thunk from 'redux-thunk'; import rootReducer from 'reducers'; -import { setup401Interceptor } from 'interceptors'; const middleware = [ thunk, // thunk middleware allows us to return promises from and receive dispatch reference in redux action creators. @@ -23,6 +22,4 @@ const composedEnhancers = compose(applyMiddleware(...middleware), ...enhancers); const store = createStore(combineReducers({ ...rootReducer }), preloadedState, composedEnhancers); -setup401Interceptor(); - export default store; From f5b3009a364ee7b8545c6ceca70d985883bb932d Mon Sep 17 00:00:00 2001 From: Pierce Trey Date: Wed, 5 May 2021 16:38:56 -0600 Subject: [PATCH 2/4] try different docker login action --- .github/workflows/release-build-publish.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-build-publish.yaml b/.github/workflows/release-build-publish.yaml index 5abb2c7..cf53f28 100644 --- a/.github/workflows/release-build-publish.yaml +++ b/.github/workflows/release-build-publish.yaml @@ -88,8 +88,12 @@ jobs: - name: Build image run: docker build . --file docker/Dockerfile --tag "p8e-ui:$VERSION" - - name: Log into registry - run: echo "${{ secrets.DOCKER_REGISTRY_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} - name: Push image run: | From 4b5d138596482119e237bd5167c6fd1c4b54aa9f Mon Sep 17 00:00:00 2001 From: Pierce Trey Date: Wed, 5 May 2021 16:41:32 -0600 Subject: [PATCH 3/4] add latest tag for non-prerelease --- .github/workflows/release-build-publish.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/release-build-publish.yaml b/.github/workflows/release-build-publish.yaml index cf53f28..7fa760a 100644 --- a/.github/workflows/release-build-publish.yaml +++ b/.github/workflows/release-build-publish.yaml @@ -107,3 +107,11 @@ jobs: docker tag "p8e-ui:$VERSION" $IMAGE_ID:$VERSION docker push $IMAGE_ID:$VERSION + + PRERELEASE=${{ github.event.release.prerelease }} + echo PRERELEASE=$PRERELEASE + + if [ "$PRERELEASE" == "false" ]; then + docker tag "p8e-ui:$VERSION" $IMAGE_ID:latest + docker push $IMAGE_ID:latest + fi \ No newline at end of file From 70f307879d087cf0f0f9f51d35368ef9e21c1035 Mon Sep 17 00:00:00 2001 From: Pierce Trey Date: Mon, 14 Jun 2021 11:09:12 -0600 Subject: [PATCH 4/4] remove logout from menu and oauth/login components --- src/App.js | 2 -- src/Constant/identity.ts | 1 - src/actions/identity-actions.ts | 25 -------------- src/components/Layout/Menu/MenuContainer.tsx | 12 +------ src/components/Login/LoginContainer.tsx | 34 -------------------- src/components/Login/index.ts | 1 - src/components/OAuth/OAuthCallback.tsx | 19 ----------- src/components/OAuth/index.ts | 1 - 8 files changed, 1 insertion(+), 94 deletions(-) delete mode 100644 src/Constant/identity.ts delete mode 100644 src/actions/identity-actions.ts delete mode 100644 src/components/Login/LoginContainer.tsx delete mode 100644 src/components/Login/index.ts delete mode 100644 src/components/OAuth/OAuthCallback.tsx delete mode 100644 src/components/OAuth/index.ts diff --git a/src/App.js b/src/App.js index ad9b7a9..b890cb0 100644 --- a/src/App.js +++ b/src/App.js @@ -12,8 +12,6 @@ const App = () => { <> - {/* */} - {/* */} diff --git a/src/Constant/identity.ts b/src/Constant/identity.ts deleted file mode 100644 index 7dd4790..0000000 --- a/src/Constant/identity.ts +++ /dev/null @@ -1 +0,0 @@ -export const OAUTH_URL = 'https://test.provenance.io/login/oauth/authorize'; \ No newline at end of file diff --git a/src/actions/identity-actions.ts b/src/actions/identity-actions.ts deleted file mode 100644 index fcada20..0000000 --- a/src/actions/identity-actions.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { createAction } from "redux-actions"; -import { P8E_URL } from "Constant/http"; -import { addError } from "./error-actions"; -import { ajaxGet } from "./xhr-actions"; - -const BASE_URL = `${P8E_URL}/external/api/v1/provenance/oauth`; - -export const LOGOUT = 'IDENTITY::LOGOUT'; -export const OAUTH_LOGIN = 'IDENTITY::OAUTH_LOGIN'; -export const OAUTH_TOKEN_EXCHANGE = 'IDENTITY::OAUTH_TOKEN_EXCHANGE'; -export const LOGIN = 'IDENTITY::LOGIN'; - -export const logout = () => async dispatch => dispatch(createAction(LOGOUT)()); - -export const oauthLogin = (redirectUrl: string) => async dispatch => ajaxGet(OAUTH_LOGIN, dispatch, `${BASE_URL}?redirectUrl=${redirectUrl}`) - .then(({ url }) => window.location.href = url); - -export const oauthTokenExchange = (code, state) => async dispatch => ajaxGet(OAUTH_TOKEN_EXCHANGE, dispatch, `${BASE_URL}/callback`, { params: { code, state } }) - .then(({ access_token, cookie_name }) => dispatch(login(access_token))) - .catch((err) => { - err.data.errors.forEach(error => dispatch(addError(error))) - return Promise.reject(err); - }); - -export const login = (jwt: string) => async dispatch => dispatch(createAction(LOGIN)(jwt)); \ No newline at end of file diff --git a/src/components/Layout/Menu/MenuContainer.tsx b/src/components/Layout/Menu/MenuContainer.tsx index e92d7db..9cbe673 100644 --- a/src/components/Layout/Menu/MenuContainer.tsx +++ b/src/components/Layout/Menu/MenuContainer.tsx @@ -1,8 +1,6 @@ import React from 'react'; -import { useDispatch } from 'react-redux'; import { withRouter } from 'react-router-dom'; -import { logout } from 'actions/identity-actions'; -import { Menu, MenuLink, MenuLinkText, MenuListItem } from './index'; +import { Menu, MenuLink } from './index'; import { Location } from 'history'; type MenuContainerProps = { @@ -10,11 +8,6 @@ type MenuContainerProps = { } const MenuContainer = ({ location }) => { - const dispatch = useDispatch(); - const handleLogout = () => { - dispatch(logout()); - }; - return (
    @@ -22,9 +15,6 @@ const MenuContainer = ({ location }) => { - - Logout -
); diff --git a/src/components/Login/LoginContainer.tsx b/src/components/Login/LoginContainer.tsx deleted file mode 100644 index a7e329b..0000000 --- a/src/components/Login/LoginContainer.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import React from 'react'; -import { useDispatch } from 'react-redux'; -import PageLayout from 'components/Layout/PageLayout'; -import styled from 'styled-components'; -import { oauthLogin } from 'actions/identity-actions'; -import { IconButton } from 'components/Button'; -import { currentLocation } from 'helpers/general'; -import { Sprite } from 'components/Sprite'; -import { useDeepLink } from 'hooks'; - -const Container = styled.div` - display: flex; - flex-grow: 1; - align-items: center; - justify-content: center; -`; - -export const LoginContainer = () => { - const dispatch = useDispatch(); - const { location, setDeepLinkLocation } = useDeepLink(); - - const handleLogin = () => { - setDeepLinkLocation(location.pathname); - dispatch(oauthLogin(currentLocation())) - }; - - return - - - Login with Provenance - - - -}; \ No newline at end of file diff --git a/src/components/Login/index.ts b/src/components/Login/index.ts deleted file mode 100644 index c0aa29e..0000000 --- a/src/components/Login/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { LoginContainer } from './LoginContainer'; \ No newline at end of file diff --git a/src/components/OAuth/OAuthCallback.tsx b/src/components/OAuth/OAuthCallback.tsx deleted file mode 100644 index 4aed68d..0000000 --- a/src/components/OAuth/OAuthCallback.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import React, { useEffect } from 'react'; -import { withRouter } from 'react-router-dom'; -import { useDispatch } from 'react-redux'; -import { parseParams } from 'helpers/params'; -import { Loader } from 'components/Loader/Loader'; -import { oauthTokenExchange } from 'actions/identity-actions'; - -const OAuthCallback = ({ location, history }) => { - const { code, state } = parseParams(location.search); - const dispatch = useDispatch(); - - useEffect(() => { - dispatch(oauthTokenExchange(code, state)).catch(() => history.push('/')) - }, [code, state, dispatch, history]) - - return -} - -export default withRouter(OAuthCallback); \ No newline at end of file diff --git a/src/components/OAuth/index.ts b/src/components/OAuth/index.ts deleted file mode 100644 index 1b9f006..0000000 --- a/src/components/OAuth/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as OAuthCallback } from './OAuthCallback'; \ No newline at end of file