diff --git a/src/components/auth/actions.js b/src/components/auth/actions.js
index 87f6ed1..70aa9fc 100644
--- a/src/components/auth/actions.js
+++ b/src/components/auth/actions.js
@@ -151,6 +151,7 @@ export function oAuthComplete(params = {}) {
if (resp.statusCode === 401 && resp.error === 'access_denied') {
// user declined permissions
return {
+ success: false,
redirectUri: resp.redirectUri
};
}
@@ -168,6 +169,18 @@ export function oAuthComplete(params = {}) {
error.acceptRequired = true;
throw error;
}
+ })
+ .then((resp) => {
+ if (resp.redirectUri === 'static_page' || resp.redirectUri === 'static_page_with_code') {
+ resp.displayCode = resp.redirectUri === 'static_page_with_code';
+ dispatch(setOAuthCode({
+ success: resp.success,
+ code: resp.code,
+ displayCode: resp.displayCode
+ }));
+ }
+
+ return resp;
});
};
}
@@ -224,6 +237,18 @@ export function setOAuthRequest(oauth) {
};
}
+export const SET_OAUTH_RESULT = 'set_oauth_result';
+export function setOAuthCode(oauth) {
+ return {
+ type: SET_OAUTH_RESULT,
+ payload: {
+ success: oauth.success,
+ code: oauth.code,
+ displayCode: oauth.displayCode
+ }
+ };
+}
+
export const SET_SCOPES = 'set_scopes';
export function setScopes(scopes) {
if (!(scopes instanceof Array)) {
diff --git a/src/components/auth/finish/Finish.jsx b/src/components/auth/finish/Finish.jsx
index 4cf2c1d..9163c48 100644
--- a/src/components/auth/finish/Finish.jsx
+++ b/src/components/auth/finish/Finish.jsx
@@ -104,9 +104,9 @@ class Finish extends Component {
}
}
-export default connect((state) => ({
- appName: state.auth.client ? state.auth.client.name : 'Undefined',
- code: 'HW9vkZA6Y4vRN3ciSm1IIDk98PHLkPPlv3jvo1MX',
- displayCode: true,
- success: true
+export default connect(({auth}) => ({
+ appName: auth.client.name,
+ code: auth.oauth.code,
+ displayCode: auth.oauth.displayCode,
+ success: auth.oauth.success
}))(Finish);
diff --git a/src/components/auth/reducer.js b/src/components/auth/reducer.js
index 402b3a3..ba33339 100644
--- a/src/components/auth/reducer.js
+++ b/src/components/auth/reducer.js
@@ -1,6 +1,6 @@
import { combineReducers } from 'redux';
-import { ERROR, SET_CLIENT, SET_OAUTH, SET_SCOPES } from './actions';
+import { ERROR, SET_CLIENT, SET_OAUTH, SET_OAUTH_RESULT, SET_SCOPES } from './actions';
export default combineReducers({
error,
@@ -56,6 +56,14 @@ function oauth(
state: payload.state
};
+ case SET_OAUTH_RESULT:
+ return {
+ ...state,
+ success: payload.success,
+ code: payload.code,
+ displayCode: payload.displayCode
+ };
+
default:
return state;
}
diff --git a/src/pages/auth/AuthPage.jsx b/src/pages/auth/AuthPage.jsx
index 6a9fa13..4ee6fbd 100644
--- a/src/pages/auth/AuthPage.jsx
+++ b/src/pages/auth/AuthPage.jsx
@@ -5,8 +5,6 @@ import { connect } from 'react-redux';
import AppInfo from 'components/auth/appInfo/AppInfo';
import PanelTransition from 'components/auth/PanelTransition';
-import Finish from 'components/auth/Finish';
-
import styles from './auth.scss';
class AuthPage extends Component {
diff --git a/src/routes.js b/src/routes.js
index 78a5347..72f4931 100644
--- a/src/routes.js
+++ b/src/routes.js
@@ -16,7 +16,7 @@ import Password from 'components/auth/password/Password';
import Logout from 'components/auth/Logout';
import PasswordChange from 'components/auth/passwordChange/PasswordChange';
import ForgotPassword from 'components/auth/forgotPassword/ForgotPassword';
-import Finish from 'components/auth/Finish';
+import Finish from 'components/auth/finish/Finish';
import authFlow from 'services/authFlow';
@@ -46,7 +46,7 @@ export default function routesFactory(store) {
-
+
diff --git a/src/services/authFlow/AuthFlow.js b/src/services/authFlow/AuthFlow.js
index b00da93..2dd239c 100644
--- a/src/services/authFlow/AuthFlow.js
+++ b/src/services/authFlow/AuthFlow.js
@@ -93,6 +93,7 @@ export default class AuthFlow {
case '/activation':
case '/password-change':
case '/oauth/permissions':
+ case '/oauth/finish':
this.setState(new LoginState());
break;
diff --git a/src/services/authFlow/CompleteState.js b/src/services/authFlow/CompleteState.js
index 153b367..6bf47f8 100644
--- a/src/services/authFlow/CompleteState.js
+++ b/src/services/authFlow/CompleteState.js
@@ -3,8 +3,18 @@ import LoginState from './LoginState';
import PermissionsState from './PermissionsState';
import ActivationState from './ActivationState';
import ChangePasswordState from './ChangePasswordState';
+import FinishState from './FinishState';
export default class CompleteState extends AbstractState {
+ constructor(options = {}) {
+ super(options);
+
+ if ('accept' in options) {
+ this.isPermissionsAccepted = options.accept;
+ this.isUserReviewedPermissions = true;
+ }
+ }
+
enter(context) {
const {auth, user} = context.getState();
@@ -15,16 +25,32 @@ export default class CompleteState extends AbstractState {
} else if (user.shouldChangePassword) {
context.setState(new ChangePasswordState());
} else if (auth.oauth) {
- context.run('oAuthComplete').then((resp) => {
- location.href = resp.redirectUri;
- }, (resp) => {
- // TODO
- if (resp.unauthorized) {
- context.setState(new LoginState());
- } else if (resp.acceptRequired) {
- context.setState(new PermissionsState());
+ if (auth.oauth.code) {
+ context.setState(new FinishState());
+ } else {
+ let data = {};
+ if (this.isUserReviewedPermissions) {
+ data.accept = this.isPermissionsAccepted;
}
- });
+ context.run('oAuthComplete', data).then((resp) => {
+ switch (resp.redirectUri) {
+ case 'static_page':
+ case 'static_page_with_code':
+ context.setState(new FinishState());
+ break;
+ default:
+ location.href = resp.redirectUri;
+ break;
+ }
+ }, (resp) => {
+ // TODO
+ if (resp.unauthorized) {
+ context.setState(new LoginState());
+ } else if (resp.acceptRequired) {
+ context.setState(new PermissionsState());
+ }
+ });
+ }
} else {
context.navigate('/');
}
diff --git a/src/services/authFlow/FinishState.js b/src/services/authFlow/FinishState.js
new file mode 100644
index 0000000..275a03e
--- /dev/null
+++ b/src/services/authFlow/FinishState.js
@@ -0,0 +1,7 @@
+import AbstractState from './AbstractState';
+
+export default class CompleteState extends AbstractState {
+ enter(context) {
+ context.navigate('/oauth/finish');
+ }
+}
diff --git a/src/services/authFlow/PermissionsState.js b/src/services/authFlow/PermissionsState.js
index 87ab524..9961b8e 100644
--- a/src/services/authFlow/PermissionsState.js
+++ b/src/services/authFlow/PermissionsState.js
@@ -1,4 +1,5 @@
import AbstractState from './AbstractState';
+import CompleteState from './CompleteState';
export default class PermissionsState extends AbstractState {
enter(context) {
@@ -14,8 +15,8 @@ export default class PermissionsState extends AbstractState {
}
process(context, accept) {
- context.run('oAuthComplete', {
+ context.setState(new CompleteState({
accept
- }).then((resp) => location.href = resp.redirectUri);
+ }));
}
}