-
Notifications
You must be signed in to change notification settings - Fork 48
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
Add Authentication/Authorization support #108
base: development
Are you sure you want to change the base?
Conversation
…ration. Add PassThroughCredentialValidator.
Hi @kreuzhofer, Apologies for the late code review! I (and I'm sure Tom as well) have been quite busy with work. Thanks for all the work, like Tom said, a pretty solid implementation, even more so with the extra hardening/ error cases you added in the last few commits. I've got a couple of comments / questions, let me know what you think:
The IAuthorizationProvider could be passed in on the http server level. That way the instantiation for RestRouteHandler and StaticFileRouteHandler wouldn't have to change and I think in most cases the authorization provider would be the same for the entire server.. The authorization provider could then be provided on the IHttpServerRequest to the RestRouteHandler and the StaticFileRouteHandler. The authorisation provider could then be added to the HttpServerConfiguration so the user can use that to specify it.
More a nice to have then a must have, but when RestControllerRequestHandler.RegisterController is called, we could parse it for Authorize attributes on the controller level and pass that into the GetRestMethods call. In the GetRestMethods method we would then either cache the authorize attribute from the controller, or the (override) authorize attribute on the method in RestControllerMethodInfo.
I think for now what you did to authorize everything if an IAuthorizationProvider is passed in is great. If we go with my suggestion of point 1 then we do lose a bit of flexibility there so I think we then need some way in the static file route handler to tell if it should execute the authorization procedure. I would then suggest passing an interface into the StaticFileRouteHandler like: The reason for the AuthorizedFilePath being a class is so in the future we can add roles / exceptions, etc.
In RestRouteHandler _authenticationProvider should actually be named _authorizationProvider. Could potentially do the parsing of the Authorisation header in a custom header (like ContentLengthHeader, etc.) In DemoCredentialValidator.AuthenticateHelper you could do Task.FromResult((username == "user" && password == "pass");) and remove the async keyword instead of adding the pragma Why does IAuthorizationProvider Task as a return type and ICredentialValidator use a IAsyncOperation as a return type? PassThroughCredentialValidator seems to not be used anywhere, are you going to do anything with this? When using AuthenticatedPerCallControllerSample TotalCallsHandled is never increased since the InstanceCreationType is PerCall. |
@kreuzhofer do you mind if I apply some of the review notes above so we can get this pull request merged back in? I think it's a nice piece of functionality to have. |
Hi @Jark, sorry for the late answer. I had some other urgent stuff, which blocked me completely from continuing on this. I will review this again and make some fixes to make it work with the development branch this week. Lets then review again. about your comments:
|
…nto development # Conflicts: # src/WebServer.UnitTests/WebServer.UnitTests.csproj # src/WebServer/project.lock.json
Hardening the Code and add unit Tests.