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

Improve authorization docs #4405

Merged
merged 1 commit into from
Jan 13, 2020
Merged

Improve authorization docs #4405

merged 1 commit into from
Jan 13, 2020

Conversation

jannyHou
Copy link
Contributor

@jannyHou jannyHou commented Jan 10, 2020

Clarify the readme file with a basic example

Base on the discussion in #4291, the basic use example in the readme file is too simple. This PR aims to improve it.

See my comment in #4291 (comment)

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

@dhmlau dhmlau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for improving the docs. I have some comments especially on the diagrams. Thanks.

@@ -28,26 +16,105 @@ npm install --save @loopback/authorization

## Basic use

Start by decorating your controller methods with `@authorize` to require the
request to be authorized.
The following example shows the basic use of authorize decorator, authorizer and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: maybe authorize decorator -> @authorize decorator ?

The following example shows the basic use of authorize decorator, authorizer and
authorization component by authorizing a client according to its role:

ASSUMING your app uses jwt as the authentication strategy, and the user
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASSUMING -> Assuming?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I was intended to emphasize the assumption, that's why I make them all upper case


In this example, we make the user profile available via dependency injection
using a key available from `@loopback/authorization` package.
First **define `role` as a property in your User model** so that after a user
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would using a numbered list be better than "first, then, ... finally"?


Here is the use case and diagram for the example:

![Use case](imgs/use-case.png)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be more helpful if the use case diagram shows the flow of the sequence. I've created a very preliminary diagram of what I have in mind:
Screen Shot 2020-01-10 at 3 58 58 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put the "endpoint" and "controller method" as text, and added your diagram to demo the use case


![Use case](imgs/use-case.png)

![Example diagram](imgs/example-diagram.png)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would certainly be helpful to include some explanation on what each box means.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intended to keep the title in each box brief :) Added explanation: The diagram shows authorization artifacts' responsibilities.

Copy link
Contributor

@hacksparrow hacksparrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good after addressing Diana's feedback.

Copy link
Member

@dhmlau dhmlau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the code snippet under "Summary and Diagram" section, there's a special character between the 2 decorators. Could you please look into it? Other than that, LGTM.

@authenticate(‘jwt’)�@authorize({allowRoles: ['ADMIN']})

@jannyHou jannyHou merged commit 52a6d71 into master Jan 13, 2020
@jannyHou jannyHou deleted the authorization/fix-doc branch January 13, 2020 21:20
@jannyHou jannyHou added this to the Jan 2020 milestone Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants