mozilla / mozilla-django-oidc

A django OpenID Connect library
https://mozilla-django-oidc.readthedocs.io
Mozilla Public License 2.0
444 stars 166 forks source link

'bytes' object has no attribute 'verify' #486

Open michaelschem opened 1 year ago

michaelschem commented 1 year ago

I believe I've got everything setup correctly, but I get the error:

AttributeError at /oidc/callback/
'bytes' object has no attribute 'verify'

Configurations:

AUTHENTICATION_BACKENDS = (
    'mozilla_django_oidc.auth.OIDCAuthenticationBackend',
    # ...
)

OIDC_RP_IDP_SIGN_KEY = "https://[REDACTED].okta.com/oauth2/v1/keys"
OIDC_RP_CLIENT_ID = "[REDACTED]"
OIDC_RP_CLIENT_SECRET = "[REDACTED]"
OIDC_OP_AUTHORIZATION_ENDPOINT = "https://[REDACTED].okta.com/oauth2/v1/authorize"
OIDC_OP_TOKEN_ENDPOINT = "https://[REDACTED].okta.com/oauth2/v1/token"
OIDC_OP_USER_ENDPOINT = "https://[REDACTED].okta.com/oauth2/v1/userinfo"
OIDC_RP_SIGN_ALGO = "RS256"
sixsax commented 1 year ago

I also using RS256. I got this error when using "OIDC_RP_IDP_SIGN_KEY". So i commented out it in favor of "OIDC_OP_JWKS_ENDPOINT" to get it works fine. It is important to commented out "OIDC_RP_IDP_SIGN_KEY" beacuse it has precendece on "OIDC_OP_JWKS_ENDPOINT".

I have no idea why "OIDC_RP_IDP_SIGN_KEY" cause exception, but seems to be related to how mozilla-django-oidc pass "key" argument to josepy library.

I'm usin Keycloak, on okta you could see at following link probably: https://developer.okta.com/docs/reference/api/apps/#list-json-web-keys

I'm using following versions: Django==4.2.3 mozilla-django-oidc==3.0.0 josepy==1.13.0

diogosilva30 commented 1 year ago

I'm having the same error with Auth0 and using OIDC_RP_IDP_SIGN_KEY

delnet72 commented 8 months ago

Ditto. Thanks @sixsax for the workaround.

JulienFS commented 1 month ago

The ̀OIDC_RP_IDP_SIGN_KEY is meant to contain a public key, not an URL to the key endpoint of your provider. You get this 'bytes' object has no attribute 'verify' error because the URL cannot be parsed into a proper public key and defaults to a byte-like key (a bit more context here : https://github.com/mozilla/mozilla-django-oidc/issues/505#issuecomment-2257988592)