# Mocked OAuth2 /userinfo endpoint normally provided via an Authorization Server (AS) / Identity Provider (IdP) # # Dovecot will query the mocked `/userinfo` endpoint with the OAuth2 bearer token it was provided during login. # If the session for the token is valid, a response returns an attribute to perform a UserDB lookup on (default: email). # `DMS_YWNjZXNzX3Rva2Vu` is the access token our OAuth2 tests expect for an authorization request to be successful. # - The token was created by base64 encoding the string `access_token`, followed by adding `DMS_` as a prefix. # - Normally an access token is a short-lived value associated to a login session. The value does not encode any real data. # It is an opaque token: https://oauth.net/2/bearer-tokens/ # NOTE: The main server config is at the end within the `:80 { ... }` block. # This is because the endpoints are extracted out into Caddy snippets, which must be defined before they're referenced. # /userinfo (route-userinfo) { vars token "DMS_YWNjZXNzX3Rva2Vu" # Expects to match an authorization header with a specific bearer token: # https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#authentication_schemes @auth header Authorization "Bearer {vars.token}" # If the provided authorization header has the expected value (bearer token), respond with this JSON payload: handle @auth { # JSON inlined via HereDoc string feature: # Dovecot OAuth2 defaults to `username_attribute = email`, which must be returned in the response to match # with the `user` credentials field that Dovecot received via base64 encoded IMAP `AUTHENTICATE` value. respond <