Skip to content

Commit

Permalink
Updated based on PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
TrevorJoelHarris committed Apr 26, 2024
1 parent 91dcf39 commit baaad3f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
22 changes: 20 additions & 2 deletions packages/teams-js/src/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,27 @@ export function validateUrl(url: URL, errorToThrow?: Error): void {
}
}

export function fullyQualifyUrlString(urlString: string): URL {
/**
* This function takes in a string that represents a full or relative path and returns a
* fully qualified URL object.
*
* Currently this is accomplished by assigning the input string to an a tag and then retrieving
* the a tag's href value. A side effect of doing this is that the string becomes a fully qualified
* URL. This is probably not how I would choose to do this, but in order to not unintentionally
* break something I've preseved the functionality here and just isolated the code to make it
* easier to mock.
*
* @example
* `fullyQualifyUrlString('https://example.com')` returns `new URL('https://example.com')`
* `fullyQualifyUrlString('helloWorld')` returns `new URL('https://example.com/helloWorld')`
* `fullyQualifyUrlString('hello%20World')` returns `new URL('https://example.com/hello%20World')`
*
* @param fullOrRelativePath A string representing a full or relative URL.
* @returns A fully qualified URL representing the input string.
*/
export function fullyQualifyUrlString(fullOrRelativePath: string): URL {
const link = document.createElement('a');
link.href = urlString;
link.href = fullOrRelativePath;
return new URL(link.href);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/teams-js/src/public/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ export namespace authentication {
height = Math.min(height, Communication.currentWindow.outerHeight - 200);

// Convert any relative URLs into absolute URLs before sending them over to the parent window
const qualifiedURL = fullyQualifyUrlString(authenticateParameters.url.replace('{oauthRedirectMethod}', 'web'));
validateUrl(qualifiedURL);
const fullyQualifiedURL = fullyQualifyUrlString(authenticateParameters.url.replace('{oauthRedirectMethod}', 'web'));
validateUrl(fullyQualifiedURL);

// We are running in the browser, so we need to center the new window ourselves
let left: number =
Expand All @@ -366,7 +366,7 @@ export namespace authentication {
top += Communication.currentWindow.outerHeight / 2 - height / 2;
// Open a child window with a desired set of standard browser features
Communication.childWindow = Communication.currentWindow.open(
qualifiedURL.href,
fullyQualifiedURL.href,
'_blank',
'toolbar=no, location=yes, status=no, menubar=no, scrollbars=yes, top=' +
top +
Expand Down

0 comments on commit baaad3f

Please sign in to comment.