Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Credential insert by name #490

Merged
merged 18 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions bin/generators/apps/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ module.exports = class extends eg.Generator {
.usage(`Usage: $0 ${process.argv[2]} create [options]`)
.example(`$0 ${process.argv[2]} create -u jdoe`)
.example(`$0 ${process.argv[2]} create -u jdoe -p 'name=mobile-app' ` +
'-p \'redirectUri=http://localhost/cb\'')
'-p \'redirectUri=http://localhost/cb\'')
.example('echo \'{"user":"jdoe","name":"mobile-app"}\'' +
` | $0 ${process.argv[2]} create --stdin`)
.example(`cat all_apps.jsonl | $0 ${process.argv[2]} create --stdin`)
` | $0 ${process.argv[2]} create --stdin`)
.example(`cat all_apps.json | $0 ${process.argv[2]} create --stdin`)
.string(['p', 'u'])
.boolean(['stdin'])
.describe('u', 'User ID or username associated with the app')
Expand Down Expand Up @@ -79,17 +79,17 @@ module.exports = class extends eg.Generator {
}

return this._insert(app, { user: argv.user })
.then(newApp => {
if (!argv.q) {
this.log.ok(`Created ${newApp.id}`);
this.stdout(JSON.stringify(newApp, null, 2));
} else {
this.stdout(newApp.id);
}
})
.catch(err => {
this.log.error((err.response && err.response.error && err.response.error.text) || err.message);
});
.then(newApp => {
if (!argv.q) {
this.log.ok(`Created ${newApp.id}`);
this.stdout(JSON.stringify(newApp, null, 2));
} else {
this.stdout(newApp.id);
}
})
.catch(err => {
this.log.error((err.response && err.response.error && err.response.error.text) || err.message);
});
};

_createFromStdin () {
Expand Down Expand Up @@ -136,9 +136,9 @@ module.exports = class extends eg.Generator {
}
}
})
.catch(err => {
this.log.error((err.response && err.response.error && err.response.error.text) || err.message);
});
.catch(err => {
this.log.error((err.response && err.response.error && err.response.error.text) || err.message);
});
});

const p = Promise.all(promises);
Expand Down Expand Up @@ -175,24 +175,24 @@ module.exports = class extends eg.Generator {
if (shouldPrompt) {
questions = missingProperties.map(p => {
const required = p.descriptor.isRequired
? ' [required]'
: '';
? ' [required]'
: '';

return {
name: p.name,
message: `Enter ${chalk.yellow(p.name)}${chalk.green(required)}:`,
default: p.defaultValue,
validate: input => !p.descriptor.isRequired ||
(!!input && p.descriptor.isRequired)
(!!input && p.descriptor.isRequired)
};
});
}
}

return this.prompt(questions)
.then(answers => {
app = Object.assign(app, answers);
return this.admin.apps.create(options.user, app);
});
.then(answers => {
app = Object.assign(app, answers);
return this.admin.apps.create(options.user, app);
});
};
};
38 changes: 19 additions & 19 deletions bin/generators/credentials/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ module.exports = class extends eg.Generator {
.usage(`Usage: $0 ${process.argv[2]} create [options]`)
.example(`$0 ${process.argv[2]} create -c jdoe -t key-auth`)
.example(`echo '{"consumer":"jdoe", "type": "key-auth"}'` +
`| $0 ${process.argv[2]} create --stdin`)
`| $0 ${process.argv[2]} create --stdin`)
.example(`echo '{"consumer":"jdoe", "type": "key-auth", "scopes":["existingScope"]}'` +
`| $0 ${process.argv[2]} create --stdin`)
.example(`cat all_apps.jsonl | $0 ${process.argv[2]} create --stdin`)
`| $0 ${process.argv[2]} create --stdin`)
.example(`cat all_apps.json | $0 ${process.argv[2]} create --stdin`)
.example(`$0 ${process.argv[2]} create -u jdoe -p 'scopes=existingScope'`)
.string(['p', 'c', 't'])
.boolean(['stdin'])
Expand Down Expand Up @@ -89,12 +89,12 @@ module.exports = class extends eg.Generator {
}

return this._insert(credential, { consumer: argv.consumer, type: argv.type })
.then(newCredential => {
this._output(newCredential);
})
.catch(err => {
this.log.error((err.response && err.response.error && err.response.error.text) || err.message);
});
.then(newCredential => {
this._output(newCredential);
})
.catch(err => {
this.log.error((err.response && err.response.error && err.response.error.text) || err.message);
});
};

_createFromStdin () {
Expand Down Expand Up @@ -143,9 +143,9 @@ module.exports = class extends eg.Generator {
.then(newCredential => {
this._output(newCredential);
})
.catch(err => {
this.log.error((err.response && err.response.error && err.response.error.text) || err.message);
});
.catch(err => {
this.log.error((err.response && err.response.error && err.response.error.text) || err.message);
});
});

const p = Promise.all(promises);
Expand Down Expand Up @@ -196,23 +196,23 @@ module.exports = class extends eg.Generator {
if (shouldPrompt) {
questions = missingProperties.map(p => {
const required = p.descriptor.isRequired
? ' [required]'
: '';
? ' [required]'
: '';

return {
name: p.name,
message: `Enter ${chalk.yellow(p.name)}${chalk.green(required)}:`,
default: p.defaultValue,
validate: input => !p.descriptor.isRequired ||
(!!input && p.descriptor.isRequired)
(!!input && p.descriptor.isRequired)
};
});
}
}
return this.prompt(questions)
.then(answers => {
credential = Object.assign(credential, answers);
return this.admin.credentials.create(options.consumer, options.type, credential);
});
.then(answers => {
credential = Object.assign(credential, answers);
return this.admin.credentials.create(options.consumer, options.type, credential);
});
};
};
20 changes: 10 additions & 10 deletions bin/generators/users/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ module.exports = class extends eg.Generator {
.usage(`Usage: $0 ${process.argv[2]} create [options]`)
.example(`$0 ${process.argv[2]} create`)
.example(`$0 ${process.argv[2]} create -p 'username=jdoe' ` +
'-p \'firstname=Jane\' -p \'lastname=Doe\'')
'-p \'firstname=Jane\' -p \'lastname=Doe\'')
.example('echo \'{"username":"jdoe","firstname":"Jane"}\'' +
` | $0 ${process.argv[2]} create --stdin`)
.example(`cat all_users.jsonl | $0 ${process.argv[2]} create --stdin`)
` | $0 ${process.argv[2]} create --stdin`)
.example(`cat all_users.json | $0 ${process.argv[2]} create --stdin`)
.string('p')
.boolean(['stdin'])
.describe('p', 'User property in the form [-p \'foo=bar\']')
Expand Down Expand Up @@ -69,9 +69,9 @@ module.exports = class extends eg.Generator {
}
}
})
.catch(err => {
this.log.error((err.response && err.response.error && err.response.error.text) || err.message);
});
.catch(err => {
this.log.error((err.response && err.response.error && err.response.error.text) || err.message);
});
});

const p = Promise.all(promises);
Expand Down Expand Up @@ -136,7 +136,7 @@ module.exports = class extends eg.Generator {
const missingProperties = [];

const configProperties = Object.assign({ username: { isRequired: true } },
models.users.properties);
models.users.properties);

Object.keys(configProperties).forEach(prop => {
const descriptor = configProperties[prop];
Expand All @@ -152,15 +152,15 @@ module.exports = class extends eg.Generator {
if (shouldPrompt) {
questions = missingProperties.map(p => {
const required = p.descriptor.isRequired
? ' [required]'
: '';
? ' [required]'
: '';

return {
name: p.name,
message: `Enter ${chalk.yellow(p.name)}${chalk.green(required)}:`,
default: p.defaultValue,
validate: input => !p.descriptor.isRequired ||
(!!input && p.descriptor.isRequired)
(!!input && p.descriptor.isRequired)
};
});
}
Expand Down
3 changes: 1 addition & 2 deletions lib/policies/basic-auth/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ function authenticateBasic (req, clientId, clientSecret, done) {
requestedScopes = req.body.scope.split(' ');
}
}

return authService.authenticateCredential(clientId, clientSecret, credentialType)
.then(consumer => {
if (!consumer) {
return done(null, false);
}
return authService.authorizeCredential(clientId, credentialType, endpointScopes || requestedScopes)
return authService.authorizeCredential(consumer.id, credentialType, endpointScopes || requestedScopes)
.then(authorized => {
if (!authorized) {
return done(null, false);
Expand Down
2 changes: 1 addition & 1 deletion lib/policies/key-auth/keyauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const services = require('../../services/index');
const logger = require('../../logger').policy;
const authService = services.auth;
const credentialType = 'key-auth';
passport.use(new LocalAPIKeyStrategy({passReqToCallback: true}, (req, apikey, done) => {
passport.use(new LocalAPIKeyStrategy({ passReqToCallback: true }, (req, apikey, done) => {
// key will look like "h1243h1kl23h4kjh:asfasqwerqw"
if (!apikey) {
return done(null, false);
Expand Down
Loading