@@ -536,7 +536,7 @@ IdentityProvider.prototype.getGraph = function (uri, callback) {
536536 * Sends a request to the OIDC Provider's Users API endpoint, to create a new
537537 * user record with the provider.
538538 * @method createOIDCUser
539- * @param trustedClient {OidcRpClient} Local/trusted OIDC client
539+ * @param oidcRpClient {OidcRpClient} Local/trusted OIDC client
540540 * @param webId {String} WebID URL of the new user to be created
541541 * @param options {Object} User options hashmap
542542 * @param options.password {String} User's signin password. NOTE: Must be 8+
@@ -546,9 +546,9 @@ IdentityProvider.prototype.getGraph = function (uri, callback) {
546546 * @return {Promise }
547547 */
548548IdentityProvider . prototype . createOIDCUser =
549- function createOIDCUser ( trustedClient , webId , options = { } ) {
550- if ( ! trustedClient ) {
551- let error = new Error ( 'No OIDC Trusted client configured' )
549+ function createOIDCUser ( oidcRpClient , webId , options = { } ) {
550+ if ( ! oidcRpClient ) {
551+ let error = new Error ( 'No OIDC RP client configured' )
552552 error . status = 500
553553 return Promise . reject ( error )
554554 }
@@ -569,14 +569,20 @@ IdentityProvider.prototype.createOIDCUser =
569569 name : options . name ,
570570 password : options . password
571571 }
572- return trustedClient . client
572+ var client = oidcRpClient . trustedClient . client
573+ return client
573574 . token ( {
574575 grant_type : 'client_credentials' ,
575576 scope : 'realm'
576577 } )
577578 . then ( ( tokenResponse ) => {
578579 let createOptions = { token : tokenResponse . access_token }
579- return trustedClient . client . users . create ( userData , createOptions )
580+ return client . users . create ( userData , createOptions )
581+ } )
582+ . catch ( ( err ) => {
583+ err . status = err . status || err . statusCode || 400
584+ err . message = err . error . message || err . error . error
585+ return Promise . reject ( err )
580586 } )
581587 }
582588
@@ -610,18 +616,19 @@ IdentityProvider.prototype.post = function post (req, res, next) {
610616 var agent = self . agent ( options )
611617 var spkac = null
612618 var cert = null
613- debug ( 'Create account with settings ' , options )
614619
615620 waterfall ( [
616621 ( callback ) => {
617622 // This is for OIDC user creation only. Move on to next step, otherwise
618623 if ( this . auth !== 'oidc' ) {
619624 return callback ( )
620625 }
621- const trustedClient = req . app . locals . oidc
622- return this . createOIDCUser ( trustedClient , agent , options )
626+ const oidcRpClient = req . app . locals . oidc
627+ return this . createOIDCUser ( oidcRpClient , agent , options )
623628 . then ( ( ) => callback ( ) )
624- . catch ( ( err ) => { callback ( err ) } )
629+ . catch ( ( err ) => {
630+ callback ( err )
631+ } )
625632 } ,
626633 ( callback ) => {
627634 // Generate a new WebID-TLS certificate, if appropriate
0 commit comments