FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

empty nonce is present in OpenIDToken claims, but should be absent · Issue #921 · authlib/authlib · GitHub

empty nonce is present in OpenIDToken claims, but should be absent #921

Description

Describe the bug

In oidc/core/grants/code.py, there is the OpenIDToken.get_authorization_code_claims method:

def get_authorization_code_claims(self, authorization_code: AuthorizationCodeMixin):
    claims = {
        "nonce": authorization_code.get_nonce(),
        "auth_time": authorization_code.get_auth_time(),
    }
    [ ... ]
    return claims

it returns the nonce as claims, regardless if it's None or a string.

According to https://openid.net/specs/openid-connect-core-1_0.html#JSONSerialization, parameters with no values should be omitted from the response.

For me, it leads to an error from the oauth4webapi client library, see panva/oauth4webapi#184 (comment). To be fair, it's not a problem for all other apps and libraries I have used.

Expected behavior

The nonce should only be added if it's not None. At least this leads to the oauth4webapi (and Immich using it) being able to successfully do OIDC against my patched authlib OIDC server.

def get_authorization_code_claims(self, authorization_code: AuthorizationCodeMixin):
        claims = {
            "auth_time": authorization_code.get_auth_time(),
        }
        if nonce := authorization_code.get_nonce():
            claims["nonce"] = nonce

        if acr := authorization_code.get_acr():
            claims["acr"] = acr

        if amr := authorization_code.get_amr():
            claims["amr"] = amr
        return claims

If you agree, I can do a PR.

Environment:

  • Authlib Version: v1.7.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL