-
Notifications
You must be signed in to change notification settings - Fork 25
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
base: master
Are you sure you want to change the base?
Bos auth #81
Conversation
…quest object for all three auth schemes
…r basic and apiKey
# Conflicts: # examples/swagger/config/default.json # examples/swagger/swagger/api-v1.yaml
# Conflicts: # examples/swagger/swagger/api-v1.yaml
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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],*/ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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: