Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tenant domain instead of siteUrl in /shares api in ODSP driver #20738

Merged
merged 5 commits into from
Apr 21, 2024
Merged
Changes from 2 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
47 changes: 37 additions & 10 deletions packages/drivers/odsp-driver/src/fetchSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils";
import {
PerformanceEvent,
isFluidError,
loggerToMonitoringContext,
wrapError,
} from "@fluidframework/telemetry-utils/internal";
import { v4 as uuid } from "uuid";
Expand Down Expand Up @@ -220,8 +221,8 @@ async function redeemSharingLink(
storageTokenFetcher: InstrumentedStorageTokenFetcher,
logger: ITelemetryLoggerExt,
forceAccessTokenViaAuthorizationHeader: boolean,
): Promise<IOdspResponse<unknown>> {
return PerformanceEvent.timedExecAsync(
): Promise<void> {
await PerformanceEvent.timedExecAsync(
logger,
{
eventName: "RedeemShareLink",
Expand All @@ -239,14 +240,40 @@ async function redeemSharingLink(
const encodedShareUrl = getEncodedShareUrl(
odspResolvedUrl.shareLinkInfo?.sharingLinkToRedeem,
);
const redeemUrl = `${odspResolvedUrl.siteUrl}/_api/v2.0/shares/${encodedShareUrl}`;
const { url, headers } = getUrlAndHeadersWithAuth(
redeemUrl,
storageToken,
forceAccessTokenViaAuthorizationHeader,
);
headers.prefer = "redeemSharingLink";
return fetchAndParseAsJSONHelper(url, { headers });

let redeemUrl: string | undefined;
async function callSharesAPI(baseUrl: string): Promise<void> {
redeemUrl = `${baseUrl}/_api/v2.0/shares/${encodedShareUrl}`;
const { url, headers } = getUrlAndHeadersWithAuth(
redeemUrl,
storageToken,
forceAccessTokenViaAuthorizationHeader,
);
headers.prefer = "redeemSharingLink";
await fetchAndParseAsJSONHelper(url, { headers });
}

const disableUsingTenantDomain = loggerToMonitoringContext(
logger,
).config.getBoolean("Fluid.Driver.Odsp.DisableUsingTenantDomainForSharesApi");
// There is an issue where if we use the siteUrl in /shares, then the allowed length of url is just a few hundred characters
// and we fail to do the redeem. But if we use the tenant domain in the url, then the allowed length becomes 2048. So, first
// construct the url for /shares using tenant domain but to be on safer side, fallback to what we were using before.
if (!disableUsingTenantDomain) {
try {
await callSharesAPI(new URL(odspResolvedUrl.siteUrl).origin);
jatgarg marked this conversation as resolved.
Show resolved Hide resolved
return;
} catch (error) {
logger.sendTelemetryEvent(
{
eventName: "ShareLinkRedeemFailedWithDomain",
length: redeemUrl?.length,
jatgarg marked this conversation as resolved.
Show resolved Hide resolved
},
error,
);
}
}
await callSharesAPI(odspResolvedUrl.siteUrl);
jatgarg marked this conversation as resolved.
Show resolved Hide resolved
}),
);
}
Expand Down
Loading