Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #36 from camfou/feat-prompt-signup
Browse files Browse the repository at this point in the history
feat: handle prompt=signup in requireSignin
  • Loading branch information
Romakita authored Jul 7, 2021
2 parents 9b49f0b + 41d332f commit 5ec5bbf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
17 changes: 11 additions & 6 deletions oidc/requireSignin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
* Module dependencies
*/

var qs = require('qs')
var sessionState = require('./sessionState')
const qs = require('qs')
const sessionState = require('./sessionState')

/**
* Require signin
*/

function requireSignin (req, res, next) {
var params = req.connectParams
var prompt = params.prompt
var responseMode = (params.response_mode && params.response_mode.trim()) ||
const params = req.connectParams
const prompt = params.prompt
const responseMode = (params.response_mode && params.response_mode.trim()) ||
(params.response_type.trim() === 'code' ||
params.response_type.trim() === 'none') ? '?' : '#'
params.response_type.trim() === 'none')
? '?'
: '#'

// redirect with error if unauthenticated
// and prompt is "none"
Expand All @@ -25,6 +27,9 @@ function requireSignin (req, res, next) {
session_state: sessionState(req.client, req.client.client_uri, req.session.opbs)
}))

// prompt to signup
} else if (!req.user && prompt === 'signup') {
res.redirect('/signup?' + qs.stringify(req.connectParams))
// prompt to sign in
} else if (!req.user || prompt === 'login') {
res.redirect('/signin?' + qs.stringify(req.connectParams))
Expand Down
9 changes: 9 additions & 0 deletions test/unit/oidc/requireSignin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ describe 'Require Signin', ->
res.redirect.should.have.been.calledWith sinon.match '/signin?'


describe 'with unauthenticated user and "signup" prompt', ->
beforeEach ->
params = prompt: 'signup', response_type: 'id_token token'
requireSignin req(params, false), res

it 'should redirect to signin', ->
res.redirect.should.have.been.calledWith sinon.match '/signup?'


describe 'with authenticated user and "login" prompt', ->
beforeEach ->
params = prompt: 'login', response_type: 'id_token token'
Expand Down

0 comments on commit 5ec5bbf

Please sign in to comment.