-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry Pick #21601 into RC.5.0 - TokenFetcher support to get authoriz…
…ationHeader (#21677) Cherry Pick #21601 ## Description There is an assumption throughout the odsp-driver code that tokens are always Bearer tokens. This is not the case. AT_POP tokens could also be used. AT_POP tokens encode url path, query params and http method into the token. This means that the token itself cannot be passed via query params (otherwise that would be a circular dependency). This PR adds authorizationHeader to TokenResponse as well as accepts request on the TokenFetcher interface. ## Breaking Changes None, all changes to public interfaces should be backwards compatible. Behavior changes: - forceAccessTokenViaAuthorizationHeader is now a no-op. - ICollabSessionOptions.unauthenticatedUserDisplayName is no longer used or passed through joinSession
- Loading branch information
Showing
23 changed files
with
294 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ import { | |
} from "./createNewUtils.js"; | ||
import { createOdspUrl } from "./createOdspUrl.js"; | ||
import { EpochTracker } from "./epochTracker.js"; | ||
import { getUrlAndHeadersWithAuth } from "./getUrlAndHeadersWithAuth.js"; | ||
import { getHeadersWithAuth } from "./getUrlAndHeadersWithAuth.js"; | ||
import { OdspDriverUrlResolver } from "./odspDriverUrlResolver.js"; | ||
import { getApiRoot } from "./odspUrlHelper.js"; | ||
import { | ||
|
@@ -50,7 +50,7 @@ const isInvalidFileName = (fileName: string): boolean => { | |
* Returns resolved url | ||
*/ | ||
export async function createNewFluidFile( | ||
getStorageToken: InstrumentedStorageTokenFetcher, | ||
getAuthHeader: InstrumentedStorageTokenFetcher, | ||
newFileInfo: INewFileInfo, | ||
logger: ITelemetryLoggerExt, | ||
createNewSummary: ISummaryTree | undefined, | ||
|
@@ -75,16 +75,10 @@ export async function createNewFluidFile( | |
let summaryHandle: string = ""; | ||
let shareLinkInfo: ShareLinkInfoType | undefined; | ||
if (createNewSummary === undefined) { | ||
itemId = await createNewEmptyFluidFile( | ||
getStorageToken, | ||
newFileInfo, | ||
logger, | ||
epochTracker, | ||
forceAccessTokenViaAuthorizationHeader, | ||
); | ||
itemId = await createNewEmptyFluidFile(getAuthHeader, newFileInfo, logger, epochTracker); | ||
} else { | ||
const content = await createNewFluidFileFromSummary( | ||
getStorageToken, | ||
getAuthHeader, | ||
newFileInfo, | ||
logger, | ||
createNewSummary, | ||
|
@@ -163,11 +157,10 @@ function extractShareLinkData( | |
} | ||
|
||
export async function createNewEmptyFluidFile( | ||
getStorageToken: InstrumentedStorageTokenFetcher, | ||
getAuthHeader: InstrumentedStorageTokenFetcher, | ||
newFileInfo: INewFileInfo, | ||
logger: ITelemetryLoggerExt, | ||
epochTracker: EpochTracker, | ||
forceAccessTokenViaAuthorizationHeader: boolean, | ||
): Promise<string> { | ||
const filePath = newFileInfo.filePath ? encodeURIComponent(`/${newFileInfo.filePath}`) : ""; | ||
// add .tmp extension to empty file (host is expected to rename) | ||
|
@@ -177,17 +170,18 @@ export async function createNewEmptyFluidFile( | |
}/items/root:/${filePath}/${encodedFilename}:/[email protected]=rename&select=id,name,parentReference`; | ||
|
||
return getWithRetryForTokenRefresh(async (options) => { | ||
const storageToken = await getStorageToken(options, "CreateNewFile"); | ||
const url = initialUrl; | ||
const method = "PUT"; | ||
const authHeader = await getAuthHeader( | ||
{ ...options, request: { url, method } }, | ||
"CreateNewFile", | ||
); | ||
|
||
return PerformanceEvent.timedExecAsync( | ||
logger, | ||
{ eventName: "createNewEmptyFile" }, | ||
async (event) => { | ||
const { url, headers } = getUrlAndHeadersWithAuth( | ||
initialUrl, | ||
storageToken, | ||
forceAccessTokenViaAuthorizationHeader, | ||
); | ||
const headers = getHeadersWithAuth(authHeader); | ||
headers["Content-Type"] = "application/json"; | ||
|
||
const fetchResponse = await runWithRetry( | ||
|
@@ -197,7 +191,7 @@ export async function createNewEmptyFluidFile( | |
{ | ||
body: undefined, | ||
headers, | ||
method: "PUT", | ||
method, | ||
}, | ||
"createFile", | ||
), | ||
|
@@ -225,7 +219,7 @@ export async function createNewEmptyFluidFile( | |
} | ||
|
||
export async function createNewFluidFileFromSummary( | ||
getStorageToken: InstrumentedStorageTokenFetcher, | ||
getAuthHeader: InstrumentedStorageTokenFetcher, | ||
newFileInfo: INewFileInfo, | ||
logger: ITelemetryLoggerExt, | ||
createNewSummary: ISummaryTree, | ||
|
@@ -249,7 +243,7 @@ export async function createNewFluidFileFromSummary( | |
|
||
return createNewFluidContainerCore<ICreateFileResponse>({ | ||
containerSnapshot, | ||
getStorageToken, | ||
getAuthHeader, | ||
logger, | ||
initialUrl, | ||
forceAccessTokenViaAuthorizationHeader, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.