Skip to content

Commit

Permalink
feat: allow overriding showLoginPage config via request header
Browse files Browse the repository at this point in the history
  • Loading branch information
whipermr5 committed Jan 28, 2022
1 parent 93c8a04 commit ffa7b8d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ $ export MOCKPASS_PORT=5156
$ export MOCKPASS_NRIC=S8979373D
$ export MOCKPASS_UEN=123456789A
$ export SHOW_LOGIN_PAGE=true # Optional, defaults to `false`
$ export SHOW_LOGIN_PAGE=true # Optional, defaults to `false`; can be overridden per request using `X-Show-Login-Page` HTTP header
# Disable signing/encryption (Optional, by default `true`)
$ export SIGN_ASSERTION=false
Expand Down
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ const options = {
assertEndpoint: process.env.CORPPASS_ASSERT_ENDPOINT,
},
},
showLoginPage: process.env.SHOW_LOGIN_PAGE === 'true',
showLoginPage: (req) => {
if (req.header('X-Show-Login-Page')) {
return req.header('X-Show-Login-Page') === 'true'
}
return process.env.SHOW_LOGIN_PAGE === 'true'
},
encryptMyInfo: process.env.ENCRYPT_MYINFO === 'true',
cryptoConfig,
}
Expand Down
2 changes: 1 addition & 1 deletion lib/express/oidc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function config(app, { showLoginPage, idpConfig, serviceProvider }) {
app.get(`/${idp.toLowerCase()}/authorize`, (req, res) => {
const redirectURI = req.query.redirect_uri
const state = encodeURIComponent(req.query.state)
if (showLoginPage) {
if (showLoginPage(req)) {
const oidc = assertions.oidc[idp]
const values = oidc.map((rawId, index) => {
const code = encodeURIComponent(
Expand Down
2 changes: 1 addition & 1 deletion lib/express/saml.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function config(
: idpConfig[idp].assertEndpoint || req.query.PartnerId
const relayState = req.query.Target
const partnerId = idpConfig[idp].id
if (showLoginPage) {
if (showLoginPage(req)) {
const saml = assertions.saml[idp]
const values = saml.map((rawId, index) => {
const samlArt = encodeURIComponent(samlArtifact(partnerId, index))
Expand Down
2 changes: 1 addition & 1 deletion lib/express/sgid.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function config(app, { showLoginPage, idpConfig, serviceProvider }) {
app.get(`${PATH_PREFIX}/authorize`, (req, res) => {
const redirectURI = req.query.redirect_uri
const state = encodeURIComponent(req.query.state)
if (showLoginPage) {
if (showLoginPage(req)) {
const oidc = assertions.oidc.singPass
const values = oidc
.filter((rawId) => assertions.myinfo.v3.personas[rawId])
Expand Down

0 comments on commit ffa7b8d

Please sign in to comment.