Skip to content

Commit

Permalink
feat: add form for custom nric based on 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
causztic committed Nov 30, 2020
1 parent fd87e05 commit bdbfb7b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/express/oidc.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function config(app, { showLoginPage, idpConfig, serviceProvider }) {
const id = idGenerator[idp](rawId)
return { id, assertURL }
})
const response = render(LOGIN_TEMPLATE, values)
const response = render(LOGIN_TEMPLATE, { values })
res.send(response)
} else {
const code = encodeURIComponent(samlArtifact(idpConfig[idp].id))
Expand Down
35 changes: 21 additions & 14 deletions lib/express/saml.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function config(
const id = idGenerator[idp](rawId)
return { id, assertURL }
})
const response = render(LOGIN_TEMPLATE, values)
const response = render(LOGIN_TEMPLATE, { values, assertEndpoint })
res.send(response)
} else {
const samlArt = encodeURIComponent(samlArtifact(idpConfig[idp].id))
Expand Down Expand Up @@ -95,18 +95,25 @@ function config(
xml,
)
console.warn(`Received SAML Artifact ${samlArtifact}`)
// Take the template and plug in the typical SingPass/CorpPass response
// Sign and encrypt the assertion
const samlArtifactBuffer = Buffer.from(samlArtifact, 'base64')
let index = samlArtifactBuffer.readInt8(samlArtifactBuffer.length - 1)
// use env NRIC when SHOW_LOGIN_PAGE is false
if (index === -1) {
index =
idp === 'singPass'
? assertions.saml.singPass.indexOf(assertions.singPassNric)
: assertions.saml.corpPass.findIndex(
(c) => c.nric === assertions.corpPassNric,
)
let nric = samlArtifact

// if not custom NRIC,
if (samlArtifact.length > 9) {
// Take the template and plug in the typical SingPass/CorpPass response
// Sign and encrypt the assertion
const samlArtifactBuffer = Buffer.from(samlArtifact, 'base64')
let index = samlArtifactBuffer.readInt8(samlArtifactBuffer.length - 1)
// use env NRIC when SHOW_LOGIN_PAGE is false
if (index === -1) {
index =
idp === 'singPass'
? assertions.saml.singPass.indexOf(assertions.singPassNric)
: assertions.saml.corpPass.findIndex(
(c) => c.nric === assertions.corpPassNric,
)
}

nric = assertions.saml[idp][index]
}

const samlArtifactResolveId = xpath.select(
Expand All @@ -115,7 +122,7 @@ function config(
)

let result = assertions.saml.create[idp](
assertions.saml[idp][index],
nric,
idpConfig[idp].id,
idpConfig[idp].assertEndpoint,
samlArtifactResolveId,
Expand Down
34 changes: 21 additions & 13 deletions static/html/login-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,28 +170,36 @@
Select username
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
{{#.}}
{{#values}}
<li><a href = "{{ assertURL }}">{{ id }}</a></li>
{{/.}}
</div>
</div>
<br>
<div class="clearfix"></div>
<div class="login__footer">
<div class="login-note">
Forgot <a aria-label="Forgot MockPass ID">MockPass ID</a> or <a aria-label="Forgot password">password</a>?
</div>
<div class="sp-reglink">
Don't have an account? <a aria-label="Register now">Register now</a>
{{/values}}
</div>
</div>
</div>

<div>

<input type="hidden" name="CSRFToken" value="null" />
</div>
</form>
<form action="{{assertEndpoint}}" method="get">
<br>
{{#assertEndpoint}}
<h6>or with your own user</h6>
<br>
<input maxlength="9" name="SAMLart" placeholder="NRIC" value="S1234567A" style="width: 100%; border: 2px solid #ccc; border-radius: 5px; background: white; color: rgb(42, 45, 51); text-align: left;">
<button autofocus="" type="submit">Login</button>
<br>
<br>
{{/assertEndpoint}}
<div class="login__footer">
<div class="login-note">
Forgot <a aria-label="Forgot MockPass ID">MockPass ID</a> or <a aria-label="Forgot password">password</a>?
</div>
<div class="sp-reglink">
Don't have an account? <a aria-label="Register now">Register now</a>
</div>
</div>
</form>
</div>
<div class="clearfix"></div>
</div>
Expand Down

0 comments on commit bdbfb7b

Please sign in to comment.