Skip to content

Conversation

@jannyHou
Copy link
Contributor

@jannyHou jannyHou commented Feb 6, 2020

Fixes: #4576

Copy from ^

I verified with an app in PR #4571

const auth_options: AuthorizationOptions = {
      defaultDecision: AuthorizationDecision.ALLOW,
      precedence: AuthorizationDecision.ALLOW,
    }
    
this.configure(AuthorizationBindings.COMPONENT).to(auth_options);

works.
The debug log:

loopback:authorization:interceptor Authorization options { defaultDecision: 'Allow', precedence: 'Allow' } +272ms

And according to the code in
https://github.com/strongloop/loopback-next/blob/6eea5e428b145cafb84a998bd53979da8c8fba07/packages/authorization/src/authorize-interceptor.ts#L38

Your solution is the correct fix. Submitting a PR to update the doc

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 👈

const binding = app.component(AuthorizationComponent);
app.configure(binding.key).to(options);
app.component(AuthorizationComponent);
app.configure(AuthorizationBindings.COMPONENT).to(options);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure that configure after component works? On other places we have to do configure before component to make it working?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@derdeka I wasn't sure, so I verified with app in #4571, you can read the PR description to see my testing result.

this.configure() is called in the app constructor, and whenever the authorization interceptor is invoked, the options will be injected. So I believe after app runs, making API calls will inject the configured options.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to suggest to switch the order to have it consistent with other docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@derdeka 👌 switched the order to have the configure before mounting component.

@jannyHou jannyHou merged commit 34ee060 into master Feb 7, 2020
@jannyHou jannyHou deleted the docfix/auth-option branch February 7, 2020 02:53
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.

fix code snippet in registering authorization component with options documentation

4 participants