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

Bos auth #81

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

Bos auth #81

wants to merge 22 commits into from

Conversation

ryshep111
Copy link

This may not be a finished product, but opening a PR to facilitate more conversation around this.

bos-passport was pulled into it's own module (not yet published to npm): https://github.com/BlueOakJS/bos-passport

Some discussion points:

Copy link
Member

@seanpk seanpk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partial review, but I think a good start to look through

var pathObj = api.paths[path];
var routePath = basePath + _convertPathToExpress(path);

//loop for http method keys, like get an post
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

var routePath = basePath + _convertPathToExpress(path);

//loop for http method keys, like get an post
_.keys(pathObj).forEach(function (method) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it a path that comes out of the pathObj?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it isn't, it is a key that corresponds to an http method

//loop for http method keys, like get an post
_.keys(pathObj).forEach(function (method) {
if (_.contains(httpMethods, method)) {
var operation = pathObj[method];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this the actual HTTP method? so the var should be method (with the previous naming change done)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in swagger the object is referred to as an 'operation' object

if (_.contains(httpMethods, method)) {
var operation = pathObj[method];
if (operation['security']) {
operation['security'].forEach(function (securityReq) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given the other uses in this file of _.forEach (and since I believe it safely passes over the case where the input is null or undefined), replace the if and the Array.forEach with _.forEach.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

operation['security'].forEach(function (securityReq) {
_.forOwn(securityReq, function (scopes, securityDefn) {
_applySecurityRequirement(app, method, routePath, securityDefn,
api.securityDefinitions[securityDefn],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the length that this is wrapping at? does it need to be wrapped again before the scopes param?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand you correctly, no because all scopes should be passed into the applySecurityRequirement function. Honestly since the scopes are only used for oauth, it makes no difference at the moment.

});
}
if (operation['x-bos-security']) {
operation['x-bos-security'].forEach(function (securityReq) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar comment as above about using _.forEach

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

operation['x-bos-security'].forEach(function (securityReq) {
_.forOwn(securityReq, function (scopes, securityDefn) {
_applyCustomSecurityRequirement(app, method, routePath, securityDefn,
api['x-bos-securityDefinitions'][securityDefn],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrapping really required before scopes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above comment

_.forOwn(securityReq, function (scopes, securityDefn) {
_applyCustomSecurityRequirement(app, method, routePath, securityDefn,
api['x-bos-securityDefinitions'][securityDefn],
/*operation['x-bos-permissions'][securityReq],*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this comment-removed parameter still here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (securityDefn['x-bos-middleware']) {
var customAuthMiddleware = loader.getConsumer('middleware', securityDefn['x-bos-middleware']);
if (!customAuthMiddleware) {
loader.loadConsumerModules('middleware',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if we always call this first? can we remove the if (!customAuthMiddleware)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: I haven't really reviewed the code below this point

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it won't do a reload from disk since it is using node's require cache behind the scenes, but still the code is more efficient if you don't attempt to reload the middleware.

securityDefn.type, securityReq);
}
}
/*//wire up path with user defined authentication method for this req
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the point of keeping all this comment-removed code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants