tests: OAuth2 - Caddyfile `imap/xoauth2` route dynamic via query string

This way is more flexible and doesn't require modifying the `Caddyfile` directly, while still easy to use.

Additionally simplifies understanding the Caddyfile to maintainers by removing the `route` directive that was required to ensure a deterministic order of vars.
This commit is contained in:
polarathene 2024-01-19 17:34:32 +13:00
parent c050c7290c
commit 2b102097fd
1 changed files with 11 additions and 7 deletions

View File

@ -52,15 +52,19 @@
} }
# /imap/xoauth2 # /imap/xoauth2
# Responds with the auth string (base64 encoded) for use with the IMAP `AUTHENTICATE` command: # Provide `user` and `access_token` values via query string parameters:
# curl http://auth.example.test/imap/xoauth2 # curl 'http://auth.example.test/imap/xoauth2?user=user1@localhost.localdomain&access_token=DMS_YWNjZXNzX3Rva2Vu'
#
# When Dovecot queries /userinfo endpoint, it will be after base64 decoding the IMAP `AUTHENTICATE` value, # When Dovecot queries /userinfo endpoint, it will be after base64 decoding the IMAP `AUTHENTICATE` value,
# and sending the `auth` value from the `credentials` variable as an HTTP Authorization header. # and sending the `auth` value from the `credentials` variable as an HTTP Authorization header.
:3000 { :3000 {
route { # The login username + OAuth2 access token prior to Base64 encoding, as per the XOAUTH2 spec:
vars token "DMS_YWNjZXNzX3Rva2Vu" # https://developers.google.com/gmail/imap/xoauth2-protocol#the_sasl_xoauth2_mechanism
vars user "user1@localhost.localdomain" vars credentials "user={query.user}\001auth=Bearer {query.access_token}\001\001"
vars credentials "user={vars.user}\001auth=Bearer {vars.token}\001\001"
# Responds with the auth string (base64 encoded) for use with the IMAP `AUTHENTICATE` command:
templates
respond "{{b64enc \"{vars.credentials}\"}}"
} }
templates templates