diff --git a/login-view/src/App.js b/login-view/src/App.js index e1dac87a..d5cb76bc 100644 --- a/login-view/src/App.js +++ b/login-view/src/App.js @@ -9,6 +9,7 @@ import LockOutlinedIcon from '@material-ui/icons/LockOutlined'; import Typography from '@material-ui/core/Typography'; import { makeStyles } from '@material-ui/core/styles'; import Container from '@material-ui/core/Container'; +import ErrorMessage from './components/ErrorMessage'; const useStyles = makeStyles(theme => ({ '@global': { @@ -48,6 +49,7 @@ function App() { const [clientId] = useState(params.get('client_id') == null ? '' : params.get('client_id')); const [userType] = useState(params.get('user_type') == null ? '' : params.get('user_type')); const [redirectUri] = useState(params.get('redirect_uri') == null ? '' : params.get('redirect_uri')); + const [error, setError] = useState(''); const handleChangeUsername = e => { setUsername(e.target.value) @@ -78,25 +80,27 @@ function App() { const formData = Object.keys(data).map(key => encodeURIComponent(key) + '=' + encodeURIComponent(data[key])).join('&'); console.log(formData); - // const formData = new URLSearchParams(); - // formData.append('j_username', {username}); - // formData.append('j_password', {password}); - - // var formData = new FormData(); - // for (var k in data) { - // formData.append(k, data[k]); - // } fetch("/oauth2/code", { method: 'POST', + redirect: 'follow', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: formData }) - .then(response => response.json()) - .then(data => console.log(data)) - .catch(error => console.log(error)); + .then(response => { + // HTTP redirect. + if (response.ok && response.redirected) { + window.location.href = response.url; + } else { + throw Error(response.statusText); + } + }) + .catch(error => { + console.log("error=", error); + setError(error.toString()); + }); }; @@ -110,6 +114,7 @@ function App() { Sign in +
({ + error: { + color: '#ff0000', + }, +})); + +function ErrorMessage(props) { + const classes = useStyles(); + return ( +
+ {props.error} +
+ ) +} + +export default ErrorMessage; diff --git a/token/src/test/java/com/networknt/oauth/token/handler/Oauth2TokenPostHandlerTest.java b/token/src/test/java/com/networknt/oauth/token/handler/Oauth2TokenPostHandlerTest.java index 259ed2a4..10a259f8 100644 --- a/token/src/test/java/com/networknt/oauth/token/handler/Oauth2TokenPostHandlerTest.java +++ b/token/src/test/java/com/networknt/oauth/token/handler/Oauth2TokenPostHandlerTest.java @@ -269,7 +269,7 @@ public void run() { Assert.assertEquals(400, statusCode); Status status = Config.getInstance().getMapper().readValue(body, Status.class); Assert.assertNotNull(status); - Assert.assertEquals("ERR12001", status.getCode()); + Assert.assertEquals("ERR11004", status.getCode()); } catch (Exception e) { logger.error("IOException: ", e); throw new ClientException(e);