Skip to content

role_check

role_check authorizes paths and methods against roles parsed by session. It is useful when one router covers many API paths with different role requirements.

yaml
server:
  http:
    middlewares:
      api_roles:
        role_check:
          allow_others: true
          redirect:
            enable: false
            url: /
          path_map:
            - regex_path: ^/api/transaction/.*
              map:
                - roles:
                    - transaction_r
                    - transaction_rw
                  methods:
                    - GET
                - roles:
                    - transaction_rw
                  write_methods: true

Fields

FieldDescription
allow_othersAllow paths that do not match any path_map.
redirect.enableRedirect instead of returning JSON 403.
redirect.urlRedirect target.
path_map[].regex_pathGo regex matched against r.URL.Path.
path_map[].mapAuthorization rules for the matched path.

Rule fields:

FieldDescription
all_methodsApply to every method.
read_methodsApply to GET, HEAD, OPTIONS, TRACE, and CONNECT.
write_methodsApply to POST, PUT, PATCH, and DELETE.
methodsExplicit method list.
rolesAllowed roles.
roles_disabledAllow the matching method group without checking roles.

Put session before role_check so claims are available.