Repository navigation
Add Cloudflare service token authentication support - #4
Merged
Merged
Conversation
Support both identity-based and service token authentication strategies for Cloudflare Zero Trust. Service tokens are detected by their JWT field structure (common_name, exp, iat, iss, sub, type) and return client_id and strategy metadata instead of user identity.
josevalim
reviewed
Mar 4, 2026
| resp = Req.request!(url: url, headers: [cookie: cookie]) | ||
| if resp.status == 200, do: {:ok, resp.body}, else: :error | ||
| defp get_metadata(token, encoded_token, url) do | ||
| if MapSet.equal?(MapSet.new(Map.keys(token.fields)), @service_token_keys) do |
Member
There was a problem hiding this comment.
I think it will be cleaner to do a pattern matching instead:
case token.fields do
%{"aud" => _, "common_name" => _, ...}
josevalim
reviewed
Mar 4, 2026
josevalim
left a comment
Member
There was a problem hiding this comment.
One comment and we can ship it!
Member
|
💚 💙 💜 💛 ❤️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Support service token authentication strategy for Cloudflare Zero Trust.
Service token authentications are detected by their JWT structure.
Currently, it returns
{conn, nil}due to400fromget_user_identityresponse, which is interpreted as a failure.Code changes
user identityvsservice tokenauthentication strategyget_user_identitytoget_metadatafor more consistencymetadataoutput (only applied for Cloudflare provider for now):strategy: either "user_identity" or "service_token";client_id: Cloudflare service token client_id