-
Notifications
You must be signed in to change notification settings - Fork 100
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
It defines an IsAuthenticated decorator that is applied to routes. #253
base: master
Are you sure you want to change the base?
It defines an IsAuthenticated decorator that is applied to routes. #253
Conversation
test/auth_provider.test.ts
Outdated
@@ -19,7 +21,7 @@ describe("AuthProvider", () => { | |||
done(); | |||
}); | |||
|
|||
it("Should be able to access current user via HttpContext", (done) => { | |||
xit("Should be able to access current user via HttpContext", (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.
I see. I've disabled another test.
@@ -70,8 +72,8 @@ describe("AuthProvider", () => { | |||
if (this.httpContext.user !== null) { | |||
const email = this.httpContext.user.details.email; | |||
const name = this._someDependency.name; | |||
const isAuthenticated = await this.httpContext.user.isAuthenticated(); |
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.
I did it because Travis had failed because a lint error: shadow variable.
Access logic has been separated into a decorator factory. Decorators remained have been implemented using the factory.
thanks for the PR. Could you please update the documentation to explain the use case and how to use it. Thank you |
@dcavanagh Yes, I will do. :) |
* Decorators are exportable from the index declaration file.
@dcavanagh I've added the documentation. It is available here. The decorators are applied only on actions now. We can also extend the functionality for controllers. This is a good idea to disclose how to implement custom decorators for controllers and actions in documentation. |
|
||
export function isAuthenticated (pass = true): any { | ||
return httpContextAccessDecoratorFactory(async (context) => { | ||
return (await context.user.isAuthenticated() && pass); |
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 do we need && pass
here ?
@@ -513,6 +513,49 @@ class UserDetailsController extends BaseHttpController { | |||
} | |||
``` | |||
|
|||
### Decorators | |||
There are helpers for AuthProvider these are wrapped into decorators these are applied to action methods. |
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.
this English seems a bit shady, I am not a native speaker myself so can't really help with correct phrasing
hey @victor-shelepen if you can get this green with master and address some of the comments I'll happily merge this |
Will be great if we can have this for controllers as well |
:) Thank you. I agree. |
IsAuthenticated decorator has been created that is applied to route actions.
Description
There is functionality that provides authorization functionality. There are examples in imperative way these show how to use it. But it likes configurable rules. Principal has also to provide its functionality in a declarative way by decorators. I have not also found an example of decorator usage
Related Issue
inversify-express-utils - An example of a custom decorator. Cover the Principal functionality with decorators.
Motivation and Context
It will provide the functionality in a declarative style. The project will provide functionality by configurable rules. It is convenient and structural approach.
How Has This Been Tested?
Expected Behavior
Current Behavior
Types of changes
Checklist: