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

docs: add guideline doc for authorize component #2721

Merged

Conversation

samarpanB
Copy link
Contributor

@samarpanB samarpanB commented Apr 10, 2019

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 machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

Copy link
Member

@bajtos bajtos left a 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

docs/site/Loopback-component.md Outdated Show resolved Hide resolved
docs/site/sidebars/lb4_sidebar.yml Outdated Show resolved Hide resolved
@bajtos bajtos requested a review from jannyHou April 12, 2019 15:01
@bajtos
Copy link
Member

bajtos commented Apr 12, 2019

Merge branch 'master' into authorisation-component-guide

Please don't use git merge, use git rebase master instead. We use linear git history with no merge commits. By rebasing early and often, you will avoid possibly costly merge conflicts later.

@raymondfeng
Copy link
Contributor

@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.

@samarpanB
Copy link
Contributor Author

Merge branch 'master' into authorisation-component-guide

Please don't use git merge, use git rebase master instead. We use linear git history with no merge commits. By rebasing early and often, you will avoid possibly costly merge conflicts later.

I'll clean up the commit history and fix as you mentioned.

@raymondfeng
Copy link
Contributor

@samarpanB There are instructions in https://loopback.io/doc/en/lb4/submitting_a_pr.html to help you tidy up the PR.

@samarpanB
Copy link
Contributor Author

@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.

@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.

@samarpanB samarpanB force-pushed the authorisation-component-guide branch 4 times, most recently from cd26500 to 1de37cb Compare April 15, 2019 06:36
@samarpanB
Copy link
Contributor Author

Fixed all issues. Please have a look. @bajtos @raymondfeng

@bajtos bajtos changed the title docs: add guideline doc for authorise component docs: add guideline doc for authorize component Apr 16, 2019
Copy link
Member

@bajtos bajtos left a 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>;
Copy link
Contributor

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?

Copy link
Contributor Author

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'])
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@samarpanB samarpanB force-pushed the authorisation-component-guide branch from 1f6c644 to 6cf945a Compare April 17, 2019 11:57
@samarpanB
Copy link
Contributor Author

@raymondfeng updated with changes as per your queries and feedback. Please have a look.

*/
export interface UserPermission {
permission: PermissionKey;
is_allowed: boolean;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@raymondfeng raymondfeng left a 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.

@samarpanB samarpanB force-pushed the authorisation-component-guide branch from a8c35ec to 3eabf4d Compare April 17, 2019 18:24
@raymondfeng
Copy link
Contributor

raymondfeng commented Apr 17, 2019

@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

@samarpanB samarpanB force-pushed the authorisation-component-guide branch 2 times, most recently from 4d3cd47 to cabf3f2 Compare April 18, 2019 03:59
@samarpanB
Copy link
Contributor Author

@raymondfeng done. Thanks !

@samarpanB samarpanB force-pushed the authorisation-component-guide branch from cabf3f2 to 8de0d79 Compare April 18, 2019 13:30
Add documentation specifying guidelines on creating an authorization component

re loopbackio#538
@samarpanB samarpanB force-pushed the authorisation-component-guide branch from 8de0d79 to 637439d Compare April 18, 2019 13:35
@samarpanB
Copy link
Contributor Author

@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 ?

  1. CalculatorService
    adds two numbers:
    Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/travis/build/strongloop/loopback-next/examples/soap-calculator/dist/tests/integration/services/calculator.service.integration.js)

  2. CalculatorService
    multiplies two numbers:
    Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/travis/build/strongloop/loopback-next/examples/soap-calculator/dist/tests/integration/services/calculator.service.integration.js)

@raymondfeng
Copy link
Contributor

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.

@nabdelgadir
Copy link
Contributor

@samarpanB I restarted it so it's passing now.

@raymondfeng raymondfeng merged commit 03e5c3b into loopbackio:master Apr 18, 2019
@raymondfeng
Copy link
Contributor

@samarpanB PR landed 👍 Thanks!

@samarpanB samarpanB deleted the authorisation-component-guide branch April 19, 2019 14:11
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);
Copy link
Contributor

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

Copy link
Contributor Author

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.

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

Successfully merging this pull request may close these issues.

4 participants