Skip to content

Commit b7244a5

Browse files
enhance sso errors fixes
1 parent 8da7e08 commit b7244a5

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

redisinsight/api/src/constants/custom-error-codes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export enum CustomErrorCodes {
1313
CloudOauthUnknownAuthorizationRequest = 11_007,
1414
CloudOauthUnexpectedError = 11_008,
1515
CloudOauthMissedRequiredData = 11_009,
16+
CloudOauthCanceled = 11_010,
1617
CloudCapiUnauthorized = 11_021,
1718
CloudCapiKeyUnauthorized = 11_022,
1819
CloudCapiKeyNotFound = 11_023,

redisinsight/api/src/constants/error-messages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export default {
8383

8484
CLOUD_CAPI_KEY_UNAUTHORIZED: 'Unable to authorize such CAPI key',
8585

86+
CLOUD_OAUTH_CANCELED: 'Authorization request was canceled.',
8687
CLOUD_OAUTH_MISCONFIGURATION: 'Authorization server misconfiguration.',
8788
CLOUD_OAUTH_GITHUB_EMAIL_PERMISSION: 'Unable to get an email from the GitHub account. Make sure that it is available.',
8889
CLOUD_OAUTH_MISSED_REQUIRED_DATA: 'Unable to get required data from the user profile.',

redisinsight/api/src/modules/cloud/auth/cloud-auth.service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import { CloudSessionService } from 'src/modules/cloud/session/cloud-session.ser
88
import { GithubIdpCloudAuthStrategy } from 'src/modules/cloud/auth/auth-strategy/github-idp.cloud.auth-strategy';
99
import { wrapHttpError } from 'src/common/utils';
1010
import {
11+
CloudOauthCanceledException,
1112
CloudOauthGithubEmailPermissionException,
1213
CloudOauthMisconfigurationException, CloudOauthMissedRequiredDataException,
14+
CloudOauthUnexpectedErrorException,
1315
CloudOauthUnknownAuthorizationRequestException,
1416
} from 'src/modules/cloud/auth/exceptions';
1517
import { CloudAuthRequestInfo, CloudAuthResponse, CloudAuthStatus } from 'src/modules/cloud/auth/models';
@@ -37,6 +39,10 @@ export class CloudAuthService {
3739
query: { error_description: string, error: string },
3840
authRequest?: CloudAuthRequest,
3941
) {
42+
if (query?.error_description?.indexOf('canceled') > -1) {
43+
return new CloudOauthCanceledException();
44+
}
45+
4046
if (
4147
query?.error_description?.indexOf('propert') > -1
4248
&& query?.error_description?.indexOf('required') > -1
@@ -52,7 +58,7 @@ export class CloudAuthService {
5258
});
5359
}
5460

55-
return new CloudOauthMisconfigurationException(undefined, {
61+
return new CloudOauthUnexpectedErrorException(undefined, {
5662
description: query.error_description,
5763
});
5864
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { HttpException, HttpExceptionOptions } from '@nestjs/common';
2+
import { CustomErrorCodes } from 'src/constants';
3+
import ERROR_MESSAGES from 'src/constants/error-messages';
4+
5+
export class CloudOauthCanceledException extends HttpException {
6+
constructor(message = ERROR_MESSAGES.CLOUD_OAUTH_CANCELED, options?: HttpExceptionOptions) {
7+
const response = {
8+
message,
9+
statusCode: 499,
10+
error: 'CloudOauthCanceled',
11+
errorCode: CustomErrorCodes.CloudOauthCanceled,
12+
};
13+
14+
super(response, response.statusCode, options);
15+
}
16+
}

redisinsight/api/src/modules/cloud/auth/exceptions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './cloud-oauth.canceled.exception';
12
export * from './cloud-oauth.misconfiguration.exception';
23
export * from './cloud-oauth.github-email-permission.exception';
34
export * from './cloud-oauth.missed-required-data.exception';

redisinsight/desktop/src/lib/cloud/cloud-oauth.handlers.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ export const getOauthIpcErrorResponse = (error: any): { status: CloudAuthStatus.
1515

1616
if (error?.getResponse) {
1717
errorResponse = error.getResponse()
18-
}
19-
20-
if (error instanceof Error) {
18+
} else if (error instanceof Error) {
2119
errorResponse = new CloudOauthUnexpectedErrorException(error.message).getResponse()
2220
}
2321

0 commit comments

Comments
 (0)