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

Support response_type: ["code", "id_token"] #139

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

seanpdoyle
Copy link

Closes omniauth/omniauth_openid_connect#105
Similar to omniauth/omniauth_openid_connect#107

Some OpenID compatible IdP support hybrid authorizations that accept a response_type with both code and id_token.

For example, Microsoft Azure B2C accepts them as a URL-encoded array:

response_type: Must include an ID token for OpenID Connect. If your web application also needs tokens for calling a web API, you can use code+id_token.

This commit extends the OmniAuth::Strategies::OpenIDConnect to encode the response_type into the query parameter as space-delimited token list when provided as an array. Similarly, when checking for missing keys in the response, iterate over the values as if they're an array.

For the originally supported single-value case, the previous behavior is maintained.

Closes [omniauth#105][]
Similar to [omniauth#107][]

Some OpenID compatible IdP support hybrid authorizations that accept a
`response_type` with both `code` and `id_token`.

For example, [Microsoft Azure B2C][] accepts them as a URL-encoded
array:

> `response_type`: Must include an ID token for OpenID Connect. If your web application also needs tokens for calling a web API, you can use `code+id_token`.

This commit extends the `OmniAuth::Strategies::OpenIDConnect` to encode
the `response_type` into the query parameter as space-delimited token
list when provided as an array. Similarly, when checking for missing
keys in the response, iterate over the values as if they're an array.

For the originally supported single-value case, the previous behavior is
maintained.

[Microsoft Azure B2C]: https://learn.microsoft.com/en-us/azure/active-directory-b2c/openid-connect#send-authentication-requests
[omniauth#105]: omniauth#105
[omniauth#107]: omniauth#107
@stanhu
Copy link
Contributor

stanhu commented Jan 23, 2023

It looks like there are some minor Rubocop failures here.

@seanpdoyle
Copy link
Author

@stanhu I've pushed up changes to resolve the Rubocop violations.

@@ -372,16 +372,18 @@ def id_token_callback_phase
end

def valid_response_type?
return true if params.key?(configured_response_type)
return true if configured_response_types.all? { |key| params[key].present? }
Copy link
Contributor

@stanhu stanhu Jan 23, 2023

Choose a reason for hiding this comment

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

In looking at https://openid.net/specs/oauth-v2-multiple-response-types-1_0.html#MultiValueResponseTypes and https://www.rfc-editor.org/rfc/rfc6749 closely, is this the correct mapping?

response_type Expected parameters
code token code, access_token, token_type
code id_token code, id_token
id_token token id_token, access_token, token_type
code id_token token code, id_token, access_token, token_type

Copy link
Contributor

Choose a reason for hiding this comment

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

So while this change is correct for code id_token, I think we probably want to handle these cases here. It looks to me that every time token shows up, access_token and token_type come along.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for laying this out @stanhu. I don't have the bandwidth to round out the other combinations, but this changeset covers our use case.

Could we merge this change, then subsequently cover the rest?

If not, feel free to take this over.

Thank you!

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.

Implicit Flow does not work
2 participants