Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tnorling committed Feb 25, 2021
1 parent 4ac08ed commit d09cd86
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 3 additions & 1 deletion lib/msal-browser/docs/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ By default `msal-browser` uses `window.location.assign` and `window.location.rep

## Writing your own implemenation

The interface contains 2 methods:
The interface contains 2 methods:

- `navigateInternal` - Called when redirecting between pages in your app e.g. redirecting from the `redirectUri` back to the page that initiated the login
- `navigateExternal` - Called when redirecting to urls external to your app e.g. AAD Sign-in prompt
Expand Down Expand Up @@ -35,6 +35,8 @@ class CustomNavigationClient extends NavigationClient {
}
```

**Note:** When providing your own implementation of `navigateInternal` you should not navigate to a different domain as this can break your authentication flow. It is intended only to be used for navigation to pages on the same domain.

### Function Parameters

- `url`: The URL MSAL.js would like to navigate to. This will be an absolute url. If you need a relative url it is your responsibility to parse this out.
Expand Down
21 changes: 10 additions & 11 deletions lib/msal-browser/src/navigation/NavigationClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@ export class NavigationClient implements INavigationClient {
* @param options
*/
navigateInternal(url: string, options: NavigationOptions): Promise<boolean>{
if (options.noHistory) {
window.location.replace(url);
} else {
window.location.assign(url);
}

return new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, options.timeout);
});
return NavigationClient.defaultNavigateWindow(url, options);
}

/**
Expand All @@ -32,6 +22,15 @@ export class NavigationClient implements INavigationClient {
* @param options
*/
navigateExternal(url: string, options: NavigationOptions): Promise<boolean> {
return NavigationClient.defaultNavigateWindow(url, options);
}

/**
* Default navigation implementation invoked by the internal and external functions
* @param url
* @param options
*/
private static defaultNavigateWindow(url: string, options: NavigationOptions): Promise<boolean> {
if (options.noHistory) {
window.location.replace(url);
} else {
Expand Down
6 changes: 6 additions & 0 deletions lib/msal-browser/src/navigation/NavigationOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@

import { ApiId } from "../utils/BrowserConstants";

/**
* Additional information passed to the navigateInternal and navigateExternal functions
*/
export type NavigationOptions = {
/** The Id of the API that initiated navigation */
apiId: ApiId
/** Suggested timeout (ms) based on the configuration provided to PublicClientApplication */
timeout: number
/** When set to true the url should not be added to the browser history */
noHistory: boolean
};

0 comments on commit d09cd86

Please sign in to comment.