mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-09-19 17:12:47 +01:00
Leave the encrypted token login path as it is on master
The direct connection string login work does not change how Mongo and Cassandra logins fail, so drop the 401/403 handling this branch added around fetchEncryptedToken along with the now unused isAuthorizationError helper.
This commit is contained in:
@@ -6,13 +6,8 @@ import ConnectImage from "../../../../images/HdeConnectCosmosDB.svg";
|
|||||||
import ErrorImage from "../../../../images/error.svg";
|
import ErrorImage from "../../../../images/error.svg";
|
||||||
import { AuthType } from "../../../AuthType";
|
import { AuthType } from "../../../AuthType";
|
||||||
import { AccessInputMetadata } from "../../../Contracts/DataModels";
|
import { AccessInputMetadata } from "../../../Contracts/DataModels";
|
||||||
import { isAuthorizationError } from "../../../Utils/AuthorizationUtils";
|
|
||||||
import { parseConnectionString } from "../Helpers/ConnectionStringParser";
|
import { parseConnectionString } from "../Helpers/ConnectionStringParser";
|
||||||
import {
|
import { fetchEncryptedToken, isAccountRestrictedForConnectionStringLogin } from "../Helpers/PortalBackendClient";
|
||||||
fetchEncryptedToken,
|
|
||||||
isAccountRestrictedForConnectionStringLogin,
|
|
||||||
PortalBackendError,
|
|
||||||
} from "../Helpers/PortalBackendClient";
|
|
||||||
import { isResourceTokenConnectionString } from "../Helpers/ResourceTokenUtils";
|
import { isResourceTokenConnectionString } from "../Helpers/ResourceTokenUtils";
|
||||||
import { isDirectConnectionStringLoginApi } from "../HostedUtils";
|
import { isDirectConnectionStringLoginApi } from "../HostedUtils";
|
||||||
|
|
||||||
@@ -78,22 +73,9 @@ export const ConnectExplorer: React.FunctionComponent<Props> = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const encryptedToken = await fetchEncryptedToken(connectionString);
|
||||||
const encryptedToken = await fetchEncryptedToken(connectionString);
|
setEncryptedToken(encryptedToken);
|
||||||
setEncryptedToken(encryptedToken);
|
setAuthType(AuthType.ConnectionString);
|
||||||
setAuthType(AuthType.ConnectionString);
|
|
||||||
} catch (error) {
|
|
||||||
// A 401 or 403 means the credentials or Portal Backend were not authorized.
|
|
||||||
// Any other failure is on the backend, so rather than block the login
|
|
||||||
// we sign in with the metadata parsed from the connection string.
|
|
||||||
if (!metadata || (error instanceof PortalBackendError && isAuthorizationError(error.statusCode))) {
|
|
||||||
setErrorMessage(getErrorMessage(error));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setAccountMetadata(metadata);
|
|
||||||
setAuthType(AuthType.ConnectionString);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<p className="connectExplorerContent connectStringText">Connect to your account with connection string</p>
|
<p className="connectExplorerContent connectStringText">Connect to your account with connection string</p>
|
||||||
|
|||||||
@@ -76,22 +76,6 @@ describe("AuthorizationUtils", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("isAuthorizationError()", () => {
|
|
||||||
it("should return true for 401 and 403", () => {
|
|
||||||
expect(AuthorizationUtils.isAuthorizationError(401)).toBe(true);
|
|
||||||
expect(AuthorizationUtils.isAuthorizationError(403)).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return false for other statuses", () => {
|
|
||||||
expect(AuthorizationUtils.isAuthorizationError(404)).toBe(false);
|
|
||||||
expect(AuthorizationUtils.isAuthorizationError(500)).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return false when there is no status", () => {
|
|
||||||
expect(AuthorizationUtils.isAuthorizationError(undefined)).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("decryptJWTToken()", () => {
|
describe("decryptJWTToken()", () => {
|
||||||
it("should throw an error if token is undefined", () => {
|
it("should throw an error if token is undefined", () => {
|
||||||
expect(() => AuthorizationUtils.decryptJWTToken(undefined)).toThrow();
|
expect(() => AuthorizationUtils.decryptJWTToken(undefined)).toThrow();
|
||||||
|
|||||||
@@ -28,10 +28,6 @@ export function getAuthorizationHeader(): ViewModels.AuthorizationTokenHeaderMet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isAuthorizationError(statusCode: number): boolean {
|
|
||||||
return statusCode === Constants.HttpStatusCodes.Unauthorized || statusCode === Constants.HttpStatusCodes.Forbidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||||
export function decryptJWTToken(token: string) {
|
export function decryptJWTToken(token: string) {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
|
|||||||
Reference in New Issue
Block a user