Skip to content

Conversation

@ozmar-salesloft
Copy link

@ozmar-salesloft ozmar-salesloft commented Sep 29, 2022

In order to adapt to the new code on Oauth2 gem we send the access_token_class as client param instead of sending it as param to get_token method

Fixes #22

@ozmar-salesloft ozmar-salesloft force-pushed the fix-token-extraction-error-with-newer-oauth-versions branch from 2859ff2 to 729c7b1 Compare September 29, 2022 21:32
- In order to adap to the new code on Oauth2 we send the
access_token_class as client param instead of sending it as param
to get_token method
@ozmar-salesloft ozmar-salesloft force-pushed the fix-token-extraction-error-with-newer-oauth-versions branch from 0e86aca to f202dfc Compare September 30, 2022 15:05
@ozmar-salesloft ozmar-salesloft marked this pull request as ready for review September 30, 2022 15:40
@Belibaste
Copy link

Thanks @ozmar-salesloft for the fix, it works well on my side. While waiting for the pull request to be merged, is there a way to use this fix without forking ? Like monkey patching ?

@marcbest
Copy link

Thanks @ozmar-salesloft, works for me as well 🏆

@irphilli
Copy link

Hi @ginjo!! 👋

Would it be possible to get this reviewed/merged? Let me know if I can help out!

@disaacs-sm
Copy link

If there a way to apply this fix while we are waiting for the next release?

We tried specify client_options: when in our initializer when setting up the slack provider, but that didn't work.

@irphilli
Copy link

If there a way to apply this fix while we are waiting for the next release?

We tried specify client_options: when in our initializer when setting up the slack provider, but that didn't work.

You can fork the repo with the fix and pull that in. Or, monkey patch with something like:

module OmniAuth
  module Slack
    module OAuth2
      class Client < ::OAuth2::Client
        # Wraps OAuth2::Client#get_token to pass in the omniauth-slack AccessToken class.
        def get_token(params, access_token_opts = {})
          debug{"params #{params}, access_token_opts #{access_token_opts}"}
          rslt = super(params, access_token_opts)
          debug{"Client #{self} built AccessToken #{rslt}"}
          rslt
        end
      end
    end
  end

  module Strategies
    class Slack < OmniAuth::Strategies::OAuth2
      option :client_options, {
        access_token_class: OmniAuth::Slack::OAuth2::AccessToken,
        auth_scheme: :basic_auth,
        authorize_url: '/oauth/v2/authorize',
        history: Array.new,
        raise_errors: false, # MUST be false to allow Slack's get-token response from v2 API.
        site: 'https://slack.com',
        token_url: '/api/oauth.v2.access',
      }
    end
  end
end

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.

Omniauth-oauth2 v.1.8.0 Causes "undefined method `expired?'"

5 participants