Skip to content

Commit

Permalink
fixes: 'appBaseUrl' option not prepended to login redirect url
Browse files Browse the repository at this point in the history
OKTA-464266
<<<Jenkins Check-In of Tested SHA: 70b8b7a for [email protected]>>>
Artifact: okta-oidc-middleware
Files changed count: 3
PR Link: "#42"
  • Loading branch information
jaredperreault-okta authored and eng-prod-CI-bot-okta committed Jan 27, 2022
1 parent 9c5e3b0 commit 4e1414e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

### Features

- [#40](https://github.com/okta/okta-oidc-middleware/pull/34) Allows passing `loginHint` to `ensureAuthenticated`
- [#40](https://github.com/okta/okta-oidc-middleware/pull/40) Allows passing `loginHint` to `ensureAuthenticated`

### Bug Fixes

- [#42](https://github.com/okta/okta-oidc-middleware/pull/42) Fixes `appBaseUrl` option not prepending to login redirect url

# 4.4.0

Expand Down
2 changes: 1 addition & 1 deletion src/oidcUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ oidcUtil.ensureAuthenticated = (context, options = {}) => {
if (req.session) {
req.session.returnTo = req.originalUrl || req.url;
}
const url = options.redirectTo || context.options.routes.login.path;
const url = options.redirectTo || (new URL(context.options.routes.login.path, context.options.appBaseUrl)).href;
return res.redirect(appendOptionsToQuery(url, options));
}

Expand Down
24 changes: 24 additions & 0 deletions test/unit/oidcUtil.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,29 @@ describe('oidcUtil', function () {
requestHandler(req, res, () => {});
expect(res.redirect).toBeCalledWith('/login?login_hint=username%40org.org');
});

it('appends `appBaseUrl` option to redirect URL', () => {
const options = {
appBaseUrl: 'http://localhost:56789',
routes: {
login: {
path: '/foo'
}
}
};

const context = {
options,
client: createMockOpenIdClient()
};

const requestHandler = oidcUtil.ensureAuthenticated(context);
let req = jest.mock();
let res = {
redirect: jest.fn()
};
requestHandler(req, res, () => {});
expect(res.redirect).toBeCalledWith('http://localhost:56789/foo');
});
});
})

0 comments on commit 4e1414e

Please sign in to comment.