Skip to content

Commit 3ed3e11

Browse files
Fix create user error handling
1 parent 8477158 commit 3ed3e11

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

lib/identity-provider.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -532,23 +532,24 @@ IdentityProvider.prototype.getGraph = function (uri, callback) {
532532
}
533533

534534
/**
535-
<<<<<<< 6477d67eec3b591c4dd226307ff634c1a26e40c6
536535
* Sends a request to the OIDC Provider's Users API endpoint, to create a new
537536
* user record with the provider.
538537
* @method createOIDCUser
539-
* @param trustedClient {OidcRpClient} Local/trusted OIDC client
538+
* @param oidcRpClient {OidcRpClient} Local/trusted OIDC client
540539
* @param webId {String} WebID URL of the new user to be created
541540
* @param options {Object} User options hashmap
542541
* @param options.password {String} User's signin password. NOTE: Must be 8+
543542
* characters, mix of alpha and numeric
544543
* @param [options.email] {String} User's email address (for recovery etc)
545544
* @param [options.name] {String} User's name
545+
* @throws {Error} HTTP 400 on missing required params, and HTTP 500 if no
546+
* oidcRpClient has been configured.
546547
* @return {Promise}
547548
*/
548549
IdentityProvider.prototype.createOIDCUser =
549-
function createOIDCUser (trustedClient, webId, options = {}) {
550-
if (!trustedClient) {
551-
let error = new Error('No OIDC Trusted client configured')
550+
function createOIDCUser (oidcRpClient, webId, options = {}) {
551+
if (!oidcRpClient) {
552+
let error = new Error('No OIDC RP client configured')
552553
error.status = 500
553554
return Promise.reject(error)
554555
}
@@ -569,14 +570,20 @@ IdentityProvider.prototype.createOIDCUser =
569570
name: options.name,
570571
password: options.password
571572
}
572-
return trustedClient.client
573+
var client = oidcRpClient.trustedClient.client
574+
return client
573575
.token({
574576
grant_type: 'client_credentials',
575577
scope: 'realm'
576578
})
577579
.then((tokenResponse) => {
578580
let createOptions = { token: tokenResponse.access_token }
579-
return trustedClient.client.users.create(userData, createOptions)
581+
return client.users.create(userData, createOptions)
582+
})
583+
.catch((err) => {
584+
err.status = err.status || err.statusCode || 400
585+
err.message = err.error.message || err.error.error
586+
return Promise.reject(err)
580587
})
581588
}
582589

@@ -610,18 +617,19 @@ IdentityProvider.prototype.post = function post (req, res, next) {
610617
var agent = self.agent(options)
611618
var spkac = null
612619
var cert = null
613-
debug('Create account with settings ', options)
614620

615621
waterfall([
616622
(callback) => {
617623
// This is for OIDC user creation only. Move on to next step, otherwise
618624
if (this.auth !== 'oidc') {
619625
return callback()
620626
}
621-
const trustedClient = req.app.locals.oidc
622-
return this.createOIDCUser(trustedClient, agent, options)
627+
const oidcRpClient = req.app.locals.oidc
628+
return this.createOIDCUser(oidcRpClient, agent, options)
623629
.then(() => callback())
624-
.catch((err) => { callback(err) })
630+
.catch((err) => {
631+
callback(err)
632+
})
625633
},
626634
(callback) => {
627635
// Generate a new WebID-TLS certificate, if appropriate

0 commit comments

Comments
 (0)