Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .storybook/addons/codeEditorAddon/codeAddon.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export const withCodeEditor = makeDecorator({
content="default-src 'self';
script-src 'self' 'unsafe-inline';
style-src 'self' 'unsafe-inline';
connect-src https://graph.microsoft.com https://graph.microsoft.us https://dod-graph.microsoft.us https://graph.microsoft.de https://microsoftgraph.chinacloudapi.cn https://canary.graph.microsoft.com https://login.microsoftonline.com https://cdn.graph.office.net https://graph.office.net 'self';
connect-src https://graph.microsoft.com https://graph.microsoft.us https://dod-graph.microsoft.us https://graph.microsoft.de https://microsoftgraph.chinacloudapi.cn https://canary.graph.microsoft.com https://login.microsoftonline.com https://graphexplorer.microsoft.com 'self';
img-src 'self' data: blob: https://*.microsoft.com https://*.microsoftonline.com https://*.sharepoint.com https://*.office.com https://*.office365.com https://*.windows.net;
font-src 'self' https://static2.sharepointonline.com;
frame-src https://login.microsoftonline.com 'self';
Expand Down
2 changes: 1 addition & 1 deletion .storybook/post-process-index-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function addCspTag(filePath) {
' '
)} 'self';style-src 'report-sample' 'unsafe-inline' ${styleHashes.join(
' '
)} 'self';font-src static2.sharepointonline.com 'self';connect-src https://cdn.graph.office.net https://graph.office.net https://login.microsoftonline.com https://graph.microsoft.com https://mgt.dev 'self';img-src data: https: 'self';frame-src https://login.microsoftonline.com 'self';default-src 'self'; base-uri 'self'; upgrade-insecure-requests; form-action 'self';report-to https://csp.microsoft.com/report/MGT-Playground"
)} 'self';font-src static2.sharepointonline.com 'self';connect-src https://graphexplorer.microsoft.com https://login.microsoftonline.com https://graph.microsoft.com https://mgt.dev 'self';img-src data: https: 'self';frame-src https://login.microsoftonline.com 'self';default-src 'self'; base-uri 'self'; upgrade-insecure-requests; form-action 'self';report-to https://csp.microsoft.com/report/MGT-Playground"
/>`;
const updatedHtmlDocument = htmlDocument.replace(
/<head>/,
Expand Down
37 changes: 3 additions & 34 deletions packages/mgt-element/src/mock/MockMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { Context, Middleware } from '@microsoft/microsoft-graph-client';
import { SessionCache, storageAvailable } from '../utils/SessionCache';

/**
* Implements Middleware for the Mock Client to escape
Expand All @@ -24,14 +23,6 @@ export class MockMiddleware implements Middleware {

private static _baseUrl: string;

private static _cache: SessionCache;
private static get _sessionCache(): SessionCache {
if (!this._cache && storageAvailable('sessionStorage')) {
this._cache = new SessionCache();
}
return this._cache;
}

public async execute(context: Context): Promise<void> {
try {
const baseUrl = await MockMiddleware.getBaseUrl();
Expand All @@ -52,39 +43,17 @@ export class MockMiddleware implements Middleware {
}

/**
* Gets the base url for the mock graph, either from the session cache or from the endpoint service
* Gets the base url for the mock graph.
*
* @static
* @return {string} the base url for the mock graph to use.
* @memberof MockMiddleware
*/
public static async getBaseUrl() {
if (!this._baseUrl) {
const sessionEndpoint = this._sessionCache?.getItem('endpointURL');
if (sessionEndpoint) {
this._baseUrl = sessionEndpoint;
} else {
try {
// get the url we should be using from the endpoint service
const response = await fetch('https://cdn.graph.office.net/en-us/graph/api/proxy/endpoint');
const base: unknown = await response.json();
if (typeof base !== 'string') {
MockMiddleware.setBaseFallbackUrl();
} else {
this._baseUrl = base + '?url=';
}
} catch {
// fallback to hardcoded value
MockMiddleware.setBaseFallbackUrl();
}
this._sessionCache?.setItem('endpointURL', this._baseUrl);
}
this._baseUrl = 'https://graphexplorer.microsoft.com/api/proxy?url=';
}

return this._baseUrl;
}

private static setBaseFallbackUrl() {
this._baseUrl = 'https://graph.office.net/en-us/graph/api/proxy?url=';
return await Promise.resolve(this._baseUrl);
}
}
Loading