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

Fixing exception when Passport keys are stored in env vars #18

Merged
merged 2 commits into from
Jun 17, 2024

Conversation

moufmouf
Copy link
Collaborator

@moufmouf moufmouf commented Jan 24, 2024

Built on top of #17

Passport keys can be stored in environment variables (https://laravel.com/docs/10.x/passport#loading-keys-from-the-environment)
but the service provider was expecting the key to exist in a file.

This commit fixes the issue by referencing the key directly from memory.

As a bonus, the keys are loaded only once now (they were loaded twice with the previous code).

Closes #14

moufmouf added 2 commits June 17, 2024 12:26
According to the OpenID connect spec:

> nonce
> String value used to associate a Client session with an ID Token, and to mitigate replay attacks. The value is passed through unmodified from the Authentication Request to the ID Token. If present in the ID Token, Clients MUST verify that the nonce Claim Value is equal to the value of the nonce parameter sent in the Authentication Request. If present in the Authentication Request, Authorization Servers MUST include a nonce Claim in the ID Token with the Claim Value being the nonce value sent in the Authentication Request. Authorization Servers SHOULD perform no other processing on nonce values used. The nonce value is a case-sensitive string.

Right now, if a client passes a "nounce", we don't give it back and
the client fails. This is happening to me right now with the client
from Matrix Synapse.

Here, I'm creating a new service (`CurrentRequestService`).
With this new service, I can get the current PSR-7 request.

I extend the AuthCodeGrant and inject this service into the extended class.
With this, I can:

- read the "nonce" from the request
- encode the "nonce" in the "code"

Then, in the `IdTokenResponse`, I read the "code" (if it is present),
extract the "nounce" and inject it in the ID token as a new claim.

The whole process is inspired by this comment: steverhoades/oauth2-openid-connect-server#47 (comment)

With those changes, nounce is correctly handled and I've successfully
tested a connection with the OpenID client from Matrix Synapse.
Passport keys can be stored in environment variables (https://laravel.com/docs/10.x/passport#loading-keys-from-the-environment)
but the service provider was expecting the key to exist in a file.

This commit fixes the issue by referencing the key directly from memory.
@moufmouf moufmouf merged commit 429fe56 into ronvanderheijden:main Jun 17, 2024
4 checks passed
@moufmouf moufmouf deleted the fix-memory-key branch June 17, 2024 10:28
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.

key is invalid excepion
1 participant