mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
Cover oauth with e2e tests and fix some old and newly introduced bugs
This commit is contained in:
@@ -182,19 +182,36 @@ function getOAuthRequest(oauthData: OauthData): OauthRequestData {
|
||||
};
|
||||
}
|
||||
|
||||
function handleOauthParamsValidation(resp: { [key: string]: any } = {}) {
|
||||
function handleOauthParamsValidation(
|
||||
resp:
|
||||
| { [key: string]: any }
|
||||
| {
|
||||
statusCode: number;
|
||||
success: false;
|
||||
error:
|
||||
| 'invalid_request'
|
||||
| 'unsupported_response_type'
|
||||
| 'invalid_scope'
|
||||
| 'invalid_client';
|
||||
parameter: string;
|
||||
} = {},
|
||||
) {
|
||||
let userMessage: string | null = null;
|
||||
|
||||
if (resp.statusCode === 400 && resp.error === 'invalid_request') {
|
||||
resp.userMessage = `Invalid request (${resp.parameter} required).`;
|
||||
userMessage = `Invalid request (${resp.parameter} required).`;
|
||||
} else if (
|
||||
resp.statusCode === 400 &&
|
||||
resp.error === 'unsupported_response_type'
|
||||
) {
|
||||
resp.userMessage = `Invalid response type '${resp.parameter}'.`;
|
||||
userMessage = `Invalid response type '${resp.parameter}'.`;
|
||||
} else if (resp.statusCode === 400 && resp.error === 'invalid_scope') {
|
||||
resp.userMessage = `Invalid scope '${resp.parameter}'.`;
|
||||
userMessage = `Invalid scope '${resp.parameter}'.`;
|
||||
} else if (resp.statusCode === 401 && resp.error === 'invalid_client') {
|
||||
resp.userMessage = 'Can not find application you are trying to authorize.';
|
||||
userMessage = 'Can not find application you are trying to authorize.';
|
||||
}
|
||||
|
||||
return Promise.reject(resp);
|
||||
return userMessage
|
||||
? Promise.reject({ ...resp, userMessage })
|
||||
: Promise.reject(resp);
|
||||
}
|
||||
|
||||
@@ -173,10 +173,11 @@ export default class AuthFlow implements AuthContext {
|
||||
const callback = this.onReady;
|
||||
this.onReady = () => {};
|
||||
|
||||
return resp.then(
|
||||
callback,
|
||||
err => err || logger.warn('State transition error', err),
|
||||
);
|
||||
return resp.then(callback, error => {
|
||||
logger.error('State transition error', { error });
|
||||
|
||||
return error;
|
||||
});
|
||||
}
|
||||
|
||||
return resp;
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
import * as actions from 'app/components/auth/actions';
|
||||
import { updateUser } from 'app/components/user/actions';
|
||||
import {
|
||||
authenticate,
|
||||
logoutAll as logout,
|
||||
remove as removeAccount,
|
||||
activate as activateAccount,
|
||||
} from 'app/components/accounts/actions';
|
||||
|
||||
import AuthFlow, { ActionsDict, AuthContext as TAuthContext } from './AuthFlow';
|
||||
|
||||
import * as actions from 'app/components/auth/actions';
|
||||
|
||||
const availableActions = {
|
||||
updateUser: actions.updateUser,
|
||||
authenticate: actions.authenticate,
|
||||
activateAccount: actions.activateAccount,
|
||||
removeAccount: actions.removeAccount,
|
||||
logout: actions.logout,
|
||||
updateUser,
|
||||
authenticate,
|
||||
activateAccount,
|
||||
removeAccount,
|
||||
logout,
|
||||
goBack: actions.goBack,
|
||||
redirect: actions.redirect,
|
||||
login: actions.login,
|
||||
|
||||
Reference in New Issue
Block a user