oauth2: undefined method `bytesize' (Incompatible with latest Faraday version)
Hi ✋🏻
With the last update: https://github.com/oauth-xx/oauth2/compare/v1.4.7...v1.4.8
NoMethodError at /auth/google_oauth2/callback
undefined method `bytesize' for {"client_id"=>"**********.apps.googleusercontent.com", "client_secret"=>"*********", "grant_type"=>"authorization_code", "code"=>"********", :redirect_uri=>"http://localhost:3000/auth/google_oauth2/callback"}:Hash
self.content_length = body.bytesize
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 13
- Comments: 20 (11 by maintainers)
Commits related to this issue
- Fix oauth2 dependency to 1.4.7 Currently, oauth2 1.4.8 includes a change that causes aptible-cli to break when attempting authorization: https://github.com/oauth-xx/oauth2/issues/572 The underlying ... — committed to dambrisco/aptible-auth-ruby by dambrisco 5 years ago
- Fix oauth2 dependency to 1.4.7 Currently, oauth2 1.4.8 includes a change that causes aptible-cli to break when attempting authorization: https://github.com/oauth-xx/oauth2/issues/572 The underlying c... — committed to dambrisco/aptible-auth-ruby by dambrisco 5 years ago
- 🚑️ Fixes #572 - Backported fix from master: https://github.com/oauth-xx/oauth2/pull/331 - 1-4-stable updated with several other parity changes from master Signed-off-by: Peter Boling <peter.boling... — committed to ruby-oauth/oauth2 by pboling 5 years ago
- Workarround for oauth2 v1.4.8 c.f. https://github.com/oauth-xx/oauth2/issues/572#issuecomment-1045088365 — committed to sue445/omniauth-chatwork by sue445 5 years ago
- 🚑️ Fixes #572 - Backported fix from master: https://github.com/oauth-xx/oauth2/pull/331 - 1-4-stable updated with several other parity changes from master Signed-off-by: Peter Boling <peter.boling... — committed to ruby-oauth/oauth2 by pboling 5 years ago
- Work around for oauth2 bug # c.f. https://github.com/oauth-xx/oauth2/issues/572#issuecomment-1045088365 gem "oauth2", github: "oauth-xx/oauth2", branch: "1-4-stable" https://github.com/oauth-xx/oauth... — committed to jcowhigjr/yelp_search_demo by jcowhigjr 5 years ago
Version 1.4.9 is released. Changelog:
Just started seeing this same problem with the omniauth-auth0 gem too when switch from 1.4.7 to 1.4.8.
With
gem "oauth2", github: "oauth-xx/oauth2", branch: "1-4-stable"it works 🥇The fix is now in
1-4-stable. Please try out the branch before I release1.4.8if you have time.Before I release, I am going to:
The fix for this issue has been in
masterbranch for 4.3 years. It is only a few lines of change. I was hoping to get version 2 ofoauth2out without needing to keep churning on the 1.4.x series, but haven’t had time to finish v2. 😦. It’s 97% complete! I was also hoping that we would not need to allow Faraday 2 upgrades in the 1.4.x series, but it creates a dependency tree snafu that is of unusual size for people who are blocked on the faraday upgrade.I am working on backporting the fix now. https://github.com/oauth-xx/oauth2/pull/331/files
The primary change between 1.4.7 and 1.4.8 was to allow users to upgrade to
faradayversions>= 2(actually< 3)… Anyone experiencing this error in a test suite, and assuming you also pulled in a faraday update, please try lockingfaradayto the previous version and keepoauth2at1.4.8. If that resolves the error it will help diagnose a fix.Alternatively, if you did not pull in a
faradayupdate when you also pulled inoauth2 1.4.8, see if the error still happens if you do pull in afaradayupdate.I am working on adding Appraisals to the build so the discrete versions of Faraday can be tested independently.
Thank you @pboling! Just wanted to note here that I upgraded today to
oauth2 2.0.6and also that version works in our application without problems. Theomniauth-gitlabversion stayed the same (4.0.0).I now upgraded
omniauth-gitlabto the recently released version4.0.0and that works withoauth2version1.4.9. I think this commit fixed the issue on the side ofomniauth-gitlab. Additionally I needed to change the configuration setting fromgitlab_url: 'https://our_gitlab_hostname/api/v4'togitlab_url: 'https://our_gitlab_hostname'.I guess the issue can be closed now.
For users of
omniauth-gitlabit may still cause confusion that the configuration setting must include/api/v4in theoauth2versions up to1.4.7and must not include it starting fromoauth2 1.4.9which also requiresomniauth-gitlab 4.0.0. @pboling Do you think this is specific toomniauth-gitlaband the necessary change of configuration should be clarified inomniauth-gitlabdocumentation or does it also affect other gems depending onoauth2?(Just for completeness: The combination of
omniauth-gitlab 4.0.0andoauth2 1.4.8produced theundefined method 'bytesize'error but that is not very relevant as there’s no reason for using version1.4.8instead1.4.9which works.)@pboling Thank you very much for the answer!
I tried changing the configuration setting to
gitlab_url: 'https://our_gitlab_hostname/'. In that case the authentication goes further, the GitLab login screen asking for username and password is shown, but the callback fails withUndefined method '[]' for nil:nilclassin the Rails application. Maybe theomniauth-gitlabgem (or thedevisegem or our own app) has been relying on the old behavior and needs some corresponding small change after the bug fix.(I’m on vacation this week and don’t have access to the system right now but if I’ll be happy to get back to it next week,)
I maintain a small in-house developed Rails application which authenticates using OAuth against our self-hosted GitLab instance (currently running GitLab version 14.8.). I’m using Debian 11, Ruby 2.7.4 and Rails 6.0.4.4.
The versions of the relevant gems in a working configuration are:
If I upgrade
oauth2to version1.4.8, it selectsfaradayversion2.2.0andfaraday-net_httpversion2.0.1and breaks with theundefined method 'bytesize'error in the Rails application. Downgradingfaradayback to1.10.0doesn’t help.If I upgrade
oauth2to version1.4.9, it selectsfaradayversion2.2.0andfaraday-net_httpversion2.0.1and breaks with a{"error":"404 Not Found"}message on the GitLab instance already before I get to the login screen. Downgradingfaradaydoesn’t help here either.Looking at the nginx access log on the GitLab server gives some more information. In the working configuration with
oauth2version1.4.7(and also withoauth2version1.4.8) the first request coming in looks like:GET /oauth/authorize?client_id=XXXXX&redirect_uri=https%3A%2F%2Four_rails_app_hostname%2Fusers%2Fauth%2Fgitlab%2Fcallback&response_type=code&scope=api&state=XXXXX HTTP/2.0When using
oauth2version1.4.9, the request looks like this:GET /api/v4/oauth/authorize?client_id=XXXXX&redirect_uri=https%3A%2F%2Four_rails_app_hostname%2Fusers%2Fauth%2Fgitlab%2Fcallback&response_type=code&scope=api&state=XXXXX HTTP/2.0In
config/config.ymlI have definedgitlab_url: 'https://our_gitlab_hostname/api/v4'as instructed in the documentation of the gemomniauth-gitlab(https://github.com/linchus/omniauth-gitlab/blob/v3.0.0/README.md).It seems that with
oauth2version1.4.9andfaradayversion2.2.0this url gets processed differently and theapi/v4part is included in the GET request - which actually sounds logical but doesn’t work. I tried taking it out from the url defined inconfig/config.yml- then the authentication goes further, the login screen asking for username and password is shown, but the callback fails withUndefined method '[]' for nil:nilclassin the Rails application.Please tell if you need any further information or have suggestions what I should try next.
@sue445 @cratown @jerryclinesmith @dambrisco @benoittgt @tfader @scottsherwood @RSO It should work with release 1.4.9. Please let me know if you find otherwise!
Keeping
oauth2 1.4.8, but droppingfaradayback to < 2 (1.9.3 specifically) fixed the problem for me.