-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
docs: add guideline doc for authorize component #2721
docs: add guideline doc for authorize component #2721
Conversation
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.
Thank you @samarpanB for the contribution!
We are using US spelling (authorization
, not authorisation
) in our docs, could you please update your content accordingly?
Also some of the CI builds are failing, please check the errors and fix the problem.
I'll leave the review of the actual content to somebody more familiar with our Authentication/Authorization story. /cc @raymondfeng @jannyHou
Please don't use |
@samarpanB Your contribution just came in time! We're evaluating a few options - #2718. Please also check out #2687. For authorization decisions, interceptors provide more metadata, which may make it more suitable for deciding if a request should be allowed for a given method. Please note authorization might be also needed for non-controller methods, such as repositories or service proxies. |
I'll clean up the commit history and fix as you mentioned. |
@samarpanB There are instructions in https://loopback.io/doc/en/lb4/submitting_a_pr.html to help you tidy up the PR. |
@raymondfeng I think the idea for this documentation was to describe a minimalist implementation of authorization as a separate component, as I have mentioned here. It could be a starter guide for those who are already working on a production ready application and need authorisation at controller methods level to begin with. BTW, I like the idea of interceptors. |
cd26500
to
1de37cb
Compare
Fixed all issues. Please have a look. @bajtos @raymondfeng |
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.
LGTM as far as I am concerned. I did not review the actual content, I'll leave that to @raymondfeng and possibly other members of @strongloop/loopback-maintainers.
* Authorize action method interface | ||
*/ | ||
export interface AuthorizeFn { | ||
(userPermissions?: string[]): Promise<boolean>; |
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.
Can we describe userPermissions
? Does it represent the granted permissions or mapped roles for the user?
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.
Description added.
decorator as below. | ||
|
||
```ts | ||
@authorize(['CanCreateRole']) |
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 it's for permissions, @authorize('canCreate')
is better.
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.
Refer the way permission keys are defined. They are specific to entities. There can be a user who is allowed to create new roles but not to create a new user. We need to have that flexibility.
1f6c644
to
6cf945a
Compare
@raymondfeng updated with changes as per your queries and feedback. Please have a look. |
*/ | ||
export interface UserPermission { | ||
permission: PermissionKey; | ||
is_allowed: boolean; |
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.
Let's use camel case, such as isAllowed
or allowed
.
Maybe it's better to use enum values, such as allow | deny
.
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.
renamed to allowed. I would prefer boolean over enum as it avoid any possibility of 3rd value which I intend 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.
@samarpanB Great writeup! I added a few more minor comments.
a8c35ec
to
3eabf4d
Compare
@samarpanB Please squash all commits into one so that we can land it. Thanks! See https://loopback.io/doc/en/lb4/submitting_a_pr.html |
4d3cd47
to
cabf3f2
Compare
@raymondfeng done. Thanks ! |
cabf3f2
to
8de0d79
Compare
Add documentation specifying guidelines on creating an authorization component re loopbackio#538
8de0d79
to
637439d
Compare
@raymondfeng it seems CI build is failing due to reasons outside of this PR. I can see below in error log. Do I need to check and fix ?
|
No, we host the test server in cloud and sometime it takes longer to wake up and causes timeout. |
@samarpanB I restarted it so it's passing now. |
@samarpanB PR landed 👍 Thanks! |
const route = this.findRoute(request); | ||
const args = await this.parseParams(request, route); | ||
// Do authentication of the user and fetch user permissions below | ||
const authUser: AuthResponse = await this.authenticateRequest(request); |
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.
@samarpanB Can you describe AuthResponse
type? See #2896
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. Just didn't want to add authentication stuff to authorization doc. hence, skipped this.
Add documentation specifying guidelines on creating an authorisation component
Related #538
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated👉 Check out how to submit a PR 👈