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

Add support for response_type id_token #32

Merged

Conversation

januszm
Copy link
Contributor

@januszm januszm commented Aug 3, 2019

Current implementation will always trigger the failure action in the client for the Implicit grant. It's because we call Omniauth::Strategy .fail! method if parameter code is missing.

Resolves: #31

For the Implicit grant, the id_token or both id_token and access_token may be returned.
NOTICE: when response_type is set to token, then access_token parameter is used (Bearer token).

A much simpler implementation to handle just the 2 cases, code or id_token could look like:

def callback_phase
  # ...
  return fail!(:missing_code, OmniAuth::OpenIDConnect::MissingCodeError.new(params['error'])) unless valid_code?
  return fail!(:missing_id_token, OmniAuth::OpenIDConnect::MissingIdTokenError.new(params['error'])) unless valid_id_token?
  # ...
end

def valid_code?
  options.response_type == 'code' ? params.key?('code') : true
end
def valid_id_token?
  options.response_type == 'id_token' ? params.key('id_token') : true
end

Let me know which option would you prefer to start with

@januszm januszm force-pushed the feature/support_more_response_types branch from bc14543 to 9baa88f Compare August 3, 2019 13:12
@januszm januszm force-pushed the feature/support_more_response_types branch from 9baa88f to abd39bb Compare August 3, 2019 13:20
@januszm
Copy link
Contributor Author

januszm commented Aug 3, 2019

I didn't have a chance and I won't test the token/access_token-only scenario unfortunately.

@januszm
Copy link
Contributor Author

januszm commented Aug 3, 2019

This looks like a minor version update, new feature, backwards compatible.

@januszm
Copy link
Contributor Author

januszm commented Aug 7, 2019

Hmm we need to return from the callback_phase just before:

client.authorization_code = authorization_code
access_token
super

Maybe with:

return something unless options.response_type.to_s == 'code'

And for Implicit Grant, super will execute:

def callback_phase
  env['omniauth.auth'] = auth_hash
  call_app!
end

# =>

def auth_hash
  hash = AuthHash.new(:provider => name, :uid => uid)
  hash.info = info unless skip_info?
  hash.credentials = credentials if credentials
  hash.extra = extra if extra
  hash
end

so we need to deal with quite a few things, like

def user_info
  @user_info ||= access_token.userinfo!
end

(define credentials, info and extra variants for Implicit Grant flow)

@januszm januszm force-pushed the feature/support_more_response_types branch from a820949 to 240c512 Compare August 8, 2019 17:35
lib/omniauth/strategies/openid_connect.rb Outdated Show resolved Hide resolved
lib/omniauth/strategies/openid_connect.rb Outdated Show resolved Hide resolved
lib/omniauth/strategies/openid_connect.rb Outdated Show resolved Hide resolved
lib/omniauth/strategies/openid_connect.rb Outdated Show resolved Hide resolved
lib/omniauth/strategies/openid_connect.rb Outdated Show resolved Hide resolved
@januszm januszm force-pushed the feature/support_more_response_types branch from 240c512 to 9664f59 Compare August 8, 2019 17:36
lib/omniauth/strategies/openid_connect.rb Outdated Show resolved Hide resolved
lib/omniauth/strategies/openid_connect.rb Outdated Show resolved Hide resolved
@januszm januszm force-pushed the feature/support_more_response_types branch 2 times, most recently from b9ff815 to 6016671 Compare August 8, 2019 19:18
lib/omniauth/strategies/openid_connect.rb Outdated Show resolved Hide resolved
lib/omniauth/strategies/openid_connect.rb Outdated Show resolved Hide resolved
lib/omniauth/strategies/openid_connect.rb Outdated Show resolved Hide resolved
lib/omniauth/strategies/openid_connect.rb Outdated Show resolved Hide resolved
@januszm januszm force-pushed the feature/support_more_response_types branch from 6016671 to ad7f075 Compare August 9, 2019 09:49
@januszm januszm changed the title Add support for response_type id_token and token Add support for response_type id_token Aug 9, 2019
@januszm januszm force-pushed the feature/support_more_response_types branch 2 times, most recently from 21612b3 to caea409 Compare August 9, 2019 13:25
@januszm januszm force-pushed the feature/support_more_response_types branch from caea409 to 8e94418 Compare August 9, 2019 13:27
@m0n9oose m0n9oose merged commit 3f52ccd into omniauth:master Aug 9, 2019
@krzysiek1507
Copy link
Contributor

krzysiek1507 commented Aug 11, 2019

It doesn't work when response_type: %i[id_token code]

undefined method `[]' for nil:NilClass
NoMethodError (undefined method `[]' for nil:NilClass):
gems/ruby-2.3.8/bundler/gems/omniauth_openid_connect-3f52ccda27ba/lib/omniauth/strategies/openid_connect.rb:319:in `valid_response_type?'
gems/ruby-2.3.8/bundler/gems/omniauth_openid_connect-3f52ccda27ba/lib/omniauth/strategies/openid_connect.rb:117:in `callback_phase'
omniauth (1.9.0) lib/omniauth/strategy.rb:238:in `callback_call'

@krzysiek1507
Copy link
Contributor

That's weird that this change was needed. 0.3.2 worked with: response_type: %i[id_token code]. I guess id didn't work with response_type: :id_token.

@Eric-Guo
Copy link
Collaborator

it didn't work with response_type: :code either

@m0n9oose
Copy link
Collaborator

It doesn't work when response_type: %i[id_token code]

Before this change, only code was a valid response type. Now it's code & id_token. So yeah, it's okay if it's not working with multiple values, there's no implementation of that.

That's weird that this change was needed. 0.3.2 worked with: response_type: %i[id_token code]. I guess id didn't work with response_type: :id_token.

Not really, we were ignoring unknown types.

it didn't work with response_type: :code either

Will check, thanks!

@januszm
Copy link
Contributor Author

januszm commented Aug 12, 2019

Changes requested in the code review did not include handling both symbol and string version of the exception key for invalid response_type param, here:

error_attrs = RESPONSE_TYPE_EXCEPTIONS[options.response_type]
we're not casting the response_type option into string (above, we define exception key as a string ('id_token' => { exception_class: OmniAuth...)

@januszm
Copy link
Contributor Author

januszm commented Aug 12, 2019

@krzysiek1507 @Eric-Guo try this: #35 , support for both symbol and string was lost during the code review phase for this PR.

@krzysiek1507
Copy link
Contributor

Before this change, only code was a valid response type. Now it's code & id_token. So yeah, it's okay if it's not working with multiple values, there's no implementation of that.

But it worked well! I need it so let me try to implement it.

@m0n9oose
Copy link
Collaborator

Still have below error:


318 319  | error_attrs = RESPONSE_TYPE_EXCEPTIONS[options.response_type]         fail!(error_attrs[:key], error_attrs[:exception_class].new(params['error']))

/Users/guochunzhong/git/oss/omniauth_openid_connect/lib/omniauth/strategies/openid_connect.rb:319:in `valid_response_type?' 
/Users/guochunzhong/git/oss/omniauth_openid_connect/lib/omniauth/strategies/openid_connect.rb:117:in `callback_phase' 

make sure you're on latest master version. It looks like you still using same version as before.

@Eric-Guo
Copy link
Collaborator

Now another error:

    def raise_out!
      raise(env['omniauth.error'] || OmniAuth::Error.new(env['omniauth.error.type']))
    end

omniauth (1.9.0) lib/omniauth/failure_endpoint.rb:25:in `raise_out!' 
omniauth (1.9.0) lib/omniauth/failure_endpoint.rb:20:in `call' 
omniauth (1.9.0) lib/omniauth/failure_endpoint.rb:12:in `call' 
omniauth (1.9.0) lib/omniauth/strategy.rb:491:in `fail!' 
/Users/guochunzhong/git/oss/omniauth_openid_connect/lib/omniauth/strategies/openid_connect.rb:319:in `valid_response_type?' 
/Users/guochunzhong/git/oss/omniauth_openid_connect/lib/omniauth/strategies/openid_connect.rb:117:in `callback_phase' 

@Eric-Guo
Copy link
Collaborator

@krzysiek1507
Copy link
Contributor

To fix response_type: :code/'code' we need to merge #34

@januszm januszm deleted the feature/support_more_response_types branch August 12, 2019 10:16
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.

Param code should only be required when response_type is code
4 participants