omniauth-slack icon indicating copy to clipboard operation
omniauth-slack copied to clipboard

Send access_token_class as client option

Open ozmar-salesloft opened this issue 3 years ago • 5 comments

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 https://github.com/ginjo/omniauth-slack/issues/22

ozmar-salesloft avatar Sep 29 '22 21:09 ozmar-salesloft

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 ?

Belibaste avatar Oct 06 '22 08:10 Belibaste

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

marcbest avatar Oct 16 '22 00:10 marcbest

Hi @ginjo!! :wave:

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

irphilli avatar Nov 15 '22 19:11 irphilli

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.

disaacs-sm avatar Dec 16 '22 15:12 disaacs-sm

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

irphilli avatar Dec 20 '22 16:12 irphilli