Hi! I currently running an configuration from kon...
# talk-oathkeeper
r
Hi! I currently running an configuration from kong <> oathkeeper <> kratos on my development. And i stumbled upon an issue where I need to fetch an
verifiable_addresses
data from kratos. Here is my sample config for oathkeeper
Copy code
- id: "api:httpbin-protected"
  upstream:
    preserve_host: true
    url: "<http://httpbin:80/anything>"
  match:
    url: "<http://oathkeeper:4455/httpbin/><.*>"
    methods:
      - GET
      - POST
      - PUT
      - PATCH
      - DELETE
  authenticators:
    - handler: cookie_session
  mutators:
    - handler: header
      config:
        headers:
          X-Verified: "{{ print .Extra.identity.verifiable_addresses }}"
  authorizer:
    handler: allow
  errors:
    - handler: redirect
      config:
        to: <http://localhost:4435/panel/login>
This will give the upstream the
X-Verified: [map[created_at:2024-02-01T07:12:38.871976Z id:7652afd1-c05b-432c-bf80-98e6d6a6efcd status:completed updated_at:2024-02-01T07:12:38.871976Z value:<mailto:test@test.com|test@test.com> verified:true verified_at:2024-02-01T07:12:57.743714Z via:email]]"
but i only want the
verified:true
part. Is it possible for oathkeeper to get the first data from the array of map? thank you 🙏
i
Sure. Use
{{ first .Extra.identity.verifiable_addresses }}
see also http://masterminds.github.io/sprig/lists.html), or e.g.
{{ index .Extra.identity.verifiable_addresses 0 }}
r
I see, thanks a lot! 😄
w
nit: while you have an authenticator on that rule and it's likely you have
require_verified_address
set, it's a good idea to use
printIndex
because that particular function will gracefully handle
nil
where
index
itself will not. not absolutely required, but a touch safer. slight downside:
printIndex
won't work with
string
indexes as would be present in maps.