diff --git a/cloudformation/template.yaml b/cloudformation/template.yaml index 789c43e33..54d49006c 100644 --- a/cloudformation/template.yaml +++ b/cloudformation/template.yaml @@ -1121,20 +1121,20 @@ Resources: SupportedIdentityProviders: [ "COGNITO" ] # should (eventually) allow people to add values CallbackURL: !If [ DevelopmentMode, [ - 'http://localhost:3000/login', - !Join [ '', [ 'https://', !GetAtt DevPortalSiteS3Bucket.RegionalDomainName ]] + 'http://localhost:3000/index.html?action=login', + !Join [ '', [ 'https://', !GetAtt DevPortalSiteS3Bucket.RegionalDomainName, '/index.html?action=login' ]] ], [ - !Join [ '', [ 'https://', !If [ UseCustomDomainName, !Ref CustomDomainName, !GetAtt DefaultCloudfrontDistribution.DomainName ], '/login' ]] + !Join [ '', [ 'https://', !If [ UseCustomDomainName, !Ref CustomDomainName, !GetAtt DefaultCloudfrontDistribution.DomainName ], '/index.html?action=login' ]] ] ] LogoutURL: !If [ DevelopmentMode, [ - 'http://localhost:3000', - !Join [ '', [ 'https://', !GetAtt DevPortalSiteS3Bucket.RegionalDomainName]] + 'http://localhost:3000/index.html?action=logout', + !Join [ '', [ 'https://', !GetAtt DevPortalSiteS3Bucket.RegionalDomainName, '/index.html?action=logout' ]] ], [ - !Join [ '', [ 'https://', !If [ UseCustomDomainName, !Ref CustomDomainName, !GetAtt DefaultCloudfrontDistribution.DomainName ]]] + !Join [ '', [ 'https://', !If [ UseCustomDomainName, !Ref CustomDomainName, !GetAtt DefaultCloudfrontDistribution.DomainName ], '/index.html?action=logout' ]] ] ] AllowedOAuthFlowsUserPoolClient: true diff --git a/dev-portal/package-lock.json b/dev-portal/package-lock.json index 2472b8f1e..bad4dd4bd 100644 --- a/dev-portal/package-lock.json +++ b/dev-portal/package-lock.json @@ -1,6 +1,6 @@ { "name": "dev-portal", - "version": "3.0.1", + "version": "3.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -4777,8 +4777,7 @@ "decode-uri-component": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz", - "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=", - "dev": true + "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=" }, "deep-equal": { "version": "1.0.1", @@ -11829,6 +11828,16 @@ "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" }, + "query-string": { + "version": "6.8.1", + "resolved": "https://registry.npmjs.org/query-string/-/query-string-6.8.1.tgz", + "integrity": "sha512-g6y0Lbq10a5pPQpjlFuojfMfV1Pd2Jw9h75ypiYPPia3Gcq2rgkKiIwbkS6JxH7c5f5u/B/sB+d13PU+g1eu4Q==", + "requires": { + "decode-uri-component": "^0.2.0", + "split-on-first": "^1.0.0", + "strict-uri-encode": "^2.0.0" + } + }, "querystring": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz", @@ -13525,6 +13534,11 @@ } } }, + "split-on-first": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/split-on-first/-/split-on-first-1.1.0.tgz", + "integrity": "sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==" + }, "split-string": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/split-string/-/split-string-3.1.0.tgz", @@ -13662,6 +13676,11 @@ "integrity": "sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI=", "dev": true }, + "strict-uri-encode": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz", + "integrity": "sha1-ucczDHBChi9rFC3CdLvMWGbONUY=" + }, "string-length": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/string-length/-/string-length-2.0.0.tgz", diff --git a/dev-portal/package.json b/dev-portal/package.json index 81ee46f73..2608c84fd 100644 --- a/dev-portal/package.json +++ b/dev-portal/package.json @@ -11,6 +11,7 @@ "mobx": "^5.5.0", "mobx-react": "^5.2.8", "object-hash": "^1.3.1", + "query-string": "^6.8.1", "react": "^16.8.4", "react-dom": "^16.8.4", "react-markdown": "^4.0.3", diff --git a/dev-portal/src/components/NavBar.jsx b/dev-portal/src/components/NavBar.jsx index b0e0ca962..6b8993a62 100755 --- a/dev-portal/src/components/NavBar.jsx +++ b/dev-portal/src/components/NavBar.jsx @@ -5,7 +5,7 @@ import React from 'react' import { Link } from 'react-router-dom' import { Menu, Image } from 'semantic-ui-react' -import { isAdmin, isAuthenticated, logout } from 'services/self' +import { isAdmin, isAuthenticated, logout, getLoginRedirectUrl } from 'services/self' import { cognitoDomain, cognitoClientId } from '../services/api' @@ -21,7 +21,7 @@ import Register from './Register' export const NavBar = observer( class NavBar extends React.Component { getCognitoUrl = (type) => { - let redirectUri = `${window.location.protocol}//${window.location.host}/login` + let redirectUri = getLoginRedirectUrl() return `${cognitoDomain}/${type}?response_type=token&client_id=${cognitoClientId}&redirect_uri=${redirectUri}` } diff --git a/dev-portal/src/components/Register.jsx b/dev-portal/src/components/Register.jsx index 985a20816..537b536cb 100644 --- a/dev-portal/src/components/Register.jsx +++ b/dev-portal/src/components/Register.jsx @@ -5,14 +5,15 @@ import React from 'react' import {Menu} from 'semantic-ui-react' import {Redirect} from 'react-router-dom' +import {getLoginRedirectUrl} from 'services/self' import {cognitoDomain, cognitoClientId} from '../services/api' export default class Register extends React.Component { - redirectUri = `${window.location.protocol}//${window.location.host}/login` + redirectUri = getLoginRedirectUrl() render() { return this.props.signedIn ? : ( Register) } -} \ No newline at end of file +} diff --git a/dev-portal/src/index.js b/dev-portal/src/index.js index bc991d91a..5f2e9effd 100644 --- a/dev-portal/src/index.js +++ b/dev-portal/src/index.js @@ -5,6 +5,8 @@ import React from 'react'; import ReactDOM from 'react-dom'; import { BrowserRouter, Route, Switch, Redirect } from 'react-router-dom' +import * as queryString from 'query-string' + // content-fragments (import here to start this ASAP) import 'services/get-fragments' @@ -62,9 +64,15 @@ class App extends React.Component { - - - } /> + { + const { action } = queryString.parse(window.location.search) + if (action === 'login') { + login() + } else if (action === 'logout') { + logout() + } + return + }} /> diff --git a/dev-portal/src/services/self.js b/dev-portal/src/services/self.js index 196e09b55..a94e45fee 100644 --- a/dev-portal/src/services/self.js +++ b/dev-portal/src/services/self.js @@ -77,6 +77,9 @@ export function login() { }) } +export const getLoginRedirectUrl = () => `${window.location.protocol}//${window.location.host}/index.html?action=login` +export const getLogoutRedirectUrl = () => `${window.location.protocol}//${window.location.host}/index.html?action=logout` + function setCredentials() { let preferred_role = jwt_decode(store.idToken)['cognito:preferred_role'] let params = { @@ -114,7 +117,8 @@ export function logout() { if (cognitoDomain) { // redirect to cognito to log out there, too - window.location = `${cognitoDomain}/logout?client_id=${cognitoClientId}&logout_uri=${window.location.protocol}//${window.location.host}`; + const redirectUrl = getLogoutRedirectUrl() + window.location = `${cognitoDomain}/logout?client_id=${cognitoClientId}&logout_uri=${redirectUrl}` } } }