mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 09:20:16 +00:00
Migrated Hosted Explorer to React (#360)
Co-authored-by: Victor Meng <vimeng@microsoft.com> Co-authored-by: Steve Faulkner <stfaul@microsoft.com>
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
import * as Constants from "../Common/Constants";
|
||||
import * as ViewModels from "../Contracts/ViewModels";
|
||||
import AuthHeadersUtil from "../Platform/Hosted/Authorization";
|
||||
import { AuthType } from "../AuthType";
|
||||
import * as Constants from "../Common/Constants";
|
||||
import * as Logger from "../Common/Logger";
|
||||
import { configContext, Platform } from "../ConfigContext";
|
||||
import * as ViewModels from "../Contracts/ViewModels";
|
||||
import { userContext } from "../UserContext";
|
||||
import { getErrorMessage } from "../Common/ErrorHandlingUtils";
|
||||
|
||||
export function getAuthorizationHeader(): ViewModels.AuthorizationTokenHeaderMetadata {
|
||||
if (window.authType === AuthType.EncryptedToken) {
|
||||
@@ -21,19 +19,6 @@ export function getAuthorizationHeader(): ViewModels.AuthorizationTokenHeaderMet
|
||||
}
|
||||
}
|
||||
|
||||
export async function getArcadiaAuthToken(
|
||||
arcadiaEndpoint: string = configContext.ARCADIA_ENDPOINT,
|
||||
tenantId?: string
|
||||
): Promise<string> {
|
||||
try {
|
||||
const token = await AuthHeadersUtil.getAccessToken(arcadiaEndpoint, tenantId);
|
||||
return token;
|
||||
} catch (error) {
|
||||
Logger.logError(getErrorMessage(error), "AuthorizationUtils/getArcadiaAuthToken");
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export function decryptJWTToken(token: string) {
|
||||
if (!token) {
|
||||
Logger.logError("Cannot decrypt token: No JWT token found", "AuthorizationUtils/decryptJWTToken");
|
||||
|
||||
@@ -42,8 +42,6 @@ export function fromContentUri(
|
||||
|
||||
matches = contentUri.match(LegacyContentUriPattern);
|
||||
if (matches && matches.length > 4) {
|
||||
console.log(`Using legacy github content uri scheme ${contentUri}`);
|
||||
|
||||
return {
|
||||
owner: matches[1],
|
||||
repo: matches[2],
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
import AuthHeadersUtil from "../Platform/Hosted/Authorization";
|
||||
import * as UserUtils from "./UserUtils";
|
||||
|
||||
describe("UserUtils", () => {
|
||||
it("getFullName works in regular data explorer (inside portal)", () => {
|
||||
const user: AuthenticationContext.UserInfo = {
|
||||
userName: "userName",
|
||||
profile: {
|
||||
name: "name"
|
||||
}
|
||||
};
|
||||
AuthHeadersUtil.getCachedUser = jest.fn().mockReturnValue(user);
|
||||
|
||||
expect(UserUtils.getFullName()).toBe("name");
|
||||
});
|
||||
|
||||
it("getFullName works in fullscreen data explorer (outside portal)", () => {
|
||||
jest.mock("./AuthorizationUtils", () => {
|
||||
(): { name: string } => ({ name: "name" });
|
||||
});
|
||||
|
||||
expect(UserUtils.getFullName()).toBe("name");
|
||||
});
|
||||
});
|
||||
@@ -1,17 +1,8 @@
|
||||
import AuthHeadersUtil from "../Platform/Hosted/Authorization";
|
||||
import { decryptJWTToken } from "./AuthorizationUtils";
|
||||
import { userContext } from "../UserContext";
|
||||
|
||||
export function getFullName(): string {
|
||||
let fullName: string;
|
||||
const user = AuthHeadersUtil.getCachedUser();
|
||||
if (user) {
|
||||
fullName = user.profile.name;
|
||||
} else {
|
||||
const authToken = userContext.authorizationToken;
|
||||
const props = decryptJWTToken(authToken);
|
||||
fullName = props.name;
|
||||
}
|
||||
|
||||
return fullName;
|
||||
const authToken = userContext.authorizationToken;
|
||||
const props = decryptJWTToken(authToken);
|
||||
return props.name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user