ramosbugs / openidconnect-rs

OpenID Connect Library for Rust
MIT License
404 stars 100 forks source link

Unexpected ParseError on exchange_token with Twitch #163

Closed richchurcher closed 5 months ago

richchurcher commented 5 months ago

Interacting with Twitch's OIDC flow. I'm able to get the code from Twitch OIDC just fine. However, the response to client.exchange_code is treated as a ParseError:

Caused by:
    scope: invalid type: sequence, expected a string at line 1 column 904

JSON response extracted from the error:

{
    "access_token": "yo...5",
    "expires_in": 14113,
    "id_token": "eyJ...G0g",
    "nonce": "Hk..._w",
    "refresh_token": "5c...4s",
    "scope": ["openid"],
    "token_type": "bearer"
}

Is Twitch simply non-compliant with the RFC? Obviously I can work around by modifying the response. This is perhaps the last obstacle, after which I should be able to contribute an example for Twitch.

richchurcher commented 5 months ago

https://www.rfc-editor.org/rfc/rfc8693#section-4.2 strongly implies it ought to be a space-delimited string.

richchurcher commented 5 months ago

Argh. https://github.com/twitchdev/issues/issues/164#issuecomment-677805012 :face_exhaling:

Thanks for your feedback regarding the scope format. While we strive to follow RFCs as closely as possible, occasionally deviations do occur. Changing our scope value from an array to a space-separated string would be a significant breaking change for existing applications. Making this change to be inline with the RFC does not outweigh the disruption it will cause, so we will not be updating the format in the current implementation. This may be something to consider in a future implementation, but as there is no action at this time, this issue will be closed.

richchurcher commented 5 months ago

I don't suppose there's any way to "pre-format" a response before the error is generated, is there? Otherwise I guess I'll keep matching on the ParseError and returning a modified response.

ramosbugs commented 5 months ago

As you've deduced, this is a problem on Twitch's end, and this crate only strives for compatibility with the published standards.

See ramosbugs/oauth2-rs#269, ramosbugs/oauth2-rs#52, and ramosbugs/oauth2-rs#146 for suggested workarounds.

richchurcher commented 5 months ago

Thanks so much! I'm so sorry I didn't find the other issues... was looking in the wrong repo.