platformOS Community

Tip: stacking authorization policies

Rich - One Orange Cow Jun 29 2021 at 01:34

Not a question .... Tip that might help someone reduce bloat.

If you are stacking auth policies (multiple for a page) and you want to reuse an existing auth policy that has a redirect on failure and don't want to create a second one or have some sort of include... you can put something in the metadata for the page to tell the auth policy to redirect or not. Because the page renders first it will pass this info upto the auth policy...

Auth policy:

---
name: policy1_redirect_disabled
redirect_to: >
  {%- if context.page.metadata.admin_redirect_disabled != true -%} /login {%- endif -%}
---

Page:

---
authorization_policies:
- policy1_redirect_disabled
- policy2_has_redirect
metadata:
  admin_redirect_disabled: true
---
  • Pawel Aug 11 2021 at 14:16
    you can put something in the metadata for the page to tell the auth policy to redirect or not. Because the page renders first it will pass this info upto the auth policy... Smart use of the system property :)
Please sign in or fill up your profile to answer a question