@@ -531,62 +531,6 @@ IdentityProvider.prototype.getGraph = function (uri, callback) {
531531 } )
532532}
533533
534- /**
535- * Sends a request to the OIDC Provider's Users API endpoint, to create a new
536- * user record with the provider.
537- * @method createOIDCUser
538- * @param oidcRpClient {OidcRpClient} Local/trusted OIDC client
539- * @param webId {String} WebID URL of the new user to be created
540- * @param options {Object} User options hashmap
541- * @param options.password {String} User's signin password. NOTE: Must be 8+
542- * characters, mix of alpha and numeric
543- * @param [options.email] {String} User's email address (for recovery etc)
544- * @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.
547- * @return {Promise }
548- */
549- IdentityProvider . prototype . createOIDCUser =
550- function createOIDCUser ( oidcRpClient , webId , options = { } ) {
551- if ( ! oidcRpClient ) {
552- let error = new Error ( 'No OIDC RP client configured' )
553- error . status = 500
554- return Promise . reject ( error )
555- }
556- if ( ! webId ) {
557- let error = new Error ( 'No WebID Url provided' )
558- error . status = 400
559- return Promise . reject ( error )
560- }
561- if ( ! options . password ) {
562- let error = new Error ( 'No password provided' )
563- error . status = 400
564- return Promise . reject ( error )
565- }
566- var userData = {
567- _id : webId ,
568- email : options . email ,
569- profile : webId ,
570- name : options . name ,
571- password : options . password
572- }
573- var client = oidcRpClient . trustedClient . client
574- return client
575- . token ( {
576- grant_type : 'client_credentials' ,
577- scope : 'realm'
578- } )
579- . then ( ( tokenResponse ) => {
580- let createOptions = { token : tokenResponse . access_token }
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 )
587- } )
588- }
589-
590534/**
591535 * Handles POST requests to /api/accounts/new, creates a new user account.
592536 * @param req
@@ -600,6 +544,7 @@ IdentityProvider.prototype.createOIDCUser =
600544 * @param [req.body.url] {String} User account URL (`username.databox.com`)
601545 * @param [req.body.username] {String} Username, passed through to `agent()` and
602546 * used in WebID URL creation if the `url` parameter is missing.
547+ * @throws {Error } HTTP 400 on missing required params, HTTP 500 on misc errors
603548 * @method post
604549 */
605550IdentityProvider . prototype . post = function post ( req , res , next ) {
@@ -625,7 +570,12 @@ IdentityProvider.prototype.post = function post (req, res, next) {
625570 return callback ( )
626571 }
627572 const oidcRpClient = req . app . locals . oidc
628- return this . createOIDCUser ( oidcRpClient , agent , options )
573+ if ( ! oidcRpClient ) {
574+ let error = new Error ( 'No OIDC RP client configured' )
575+ error . status = 500
576+ return callback ( error )
577+ }
578+ return oidcRpClient . createOIDCUser ( agent , options )
629579 . then ( ( ) => callback ( ) )
630580 . catch ( ( err ) => {
631581 callback ( err )
0 commit comments