Skip to content
This repository has been archived by the owner on Jun 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #18 from Azure-Samples/derisen
Browse files Browse the repository at this point in the history
fix redirect route handler invalid route path issue
  • Loading branch information
derisen authored Jul 7, 2021
2 parents 87dc34d + 9b840bb commit 36e6ecf
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 9 deletions.
4 changes: 2 additions & 2 deletions demo/App/routes/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ module.exports = (authProvider) => {
mainController.getTenantPage
); // get token for this route to call web API

// unauthorized
// error
router.get('/error', (req, res) => res.redirect('/401.html'));

// error
// unauthorized
router.get('/unauthorized', (req, res) => res.redirect('/500.html'));

// 404
Expand Down
6 changes: 6 additions & 0 deletions dist/UrlUtils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ export declare class UrlUtils {
* @returns {string}
*/
static ensureAbsoluteUrl: (req: Request, url: string) => string;
/**
* Gets the path segment from a given URL
* @param {string} url: a given URL
* @returns {string}
*/
static getPathFromUrl: (url: string) => string;
}
13 changes: 12 additions & 1 deletion dist/msal-express-wrapper.cjs.development.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/msal-express-wrapper.cjs.development.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/msal-express-wrapper.cjs.production.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/msal-express-wrapper.cjs.production.min.js.map

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion dist/msal-express-wrapper.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/msal-express-wrapper.esm.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/AuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class AuthProvider {
const appRouter = express.Router();

// handle redirect
appRouter.get(this.appSettings.authRoutes.redirect, this.handleRedirect());
appRouter.get(UrlUtils.getPathFromUrl(this.appSettings.authRoutes.redirect), this.handleRedirect());

if (this.appSettings.authRoutes.frontChannelLogout) {
/**
Expand Down
10 changes: 10 additions & 0 deletions src/UrlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ export class UrlUtils {
return url;
}
};

/**
* Gets the path segment from a given URL
* @param {string} url: a given URL
* @returns {string}
*/
static getPathFromUrl = (url: string): string => {
const urlComponents: IUri = new UrlString(url).getUrlComponents();
return `/${urlComponents.PathSegments.join("/")}`;
};
}

0 comments on commit 36e6ecf

Please sign in to comment.