Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate OpenID claims #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xavier
Copy link

@xavier xavier commented Jul 27, 2020

This change resolves #35 by adding som basic ID token claims validation.

It should not be a breaking change unless this library is being used to validate non OIDC-compliant ID Tokens with the verify/3 function.

@@ -266,6 +283,43 @@ defmodule OpenIDConnect do
end
end

defp verify_claims(claims, config) do
with :ok <- verify_exp_claim(claims, exp_leeway(config)),
:ok <- verify_aud_claim(claims, client_id(config)) do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the client_id always going be the same as the expected aud? I was under the impression these could be different. Apologies in advance if this comment betrays my ignorance :).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From https://openid.net/specs/openid-connect-core-1_0.html#IDToken (emphasis mine)

aud
REQUIRED. Audience(s) that this ID Token is intended for. It MUST contain the OAuth 2.0 client_id of the Relying Party as an audience value. It MAY also contain identifiers for other audiences. In the general case, the aud value is an array of case sensitive strings. In the common special case when there is one audience, the aud value MAY be a single case sensitive string.

The audience_matches? private helper function handles the special case when the aud claim may contain multiple audiences.

:ok <- verify_aud_claim(claims, client_id(config)) do
{:ok, claims}
end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps being able to opt out of these verifications would be useful to some. Certainly on board with secure by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenID claims validation
2 participants