Skip to content

Commit 97e40f8

Browse files
authored
Fix requiring of oauth2 (#86)
The changes in #83 (which were released in v4.1.0) moved the `OauthClient` class (which uses the `oauth2` gem) from the Rails applications into the `rpi_auth` gem. At that point the `oauth2` gem was made a direct dependency of `rpi_auth` and the direct dependency on `oauth2` was removed from the Rails applications. I _think_ this meant that the `oauth2` gem was no longer being required automatically. And, although individual files in the `oauth2` gem were being required from individual files in `rpi_auth`, this meant that not all of the files in `oauth2` were being required. In particular, the `lib/oauth2.rb` file which defines the top-level `OAuth2` module and the `OAuth2.config` method was no longer being required. This led to exceptions like [this one][1] in `experience-cs` when `RpiAuth::OauthClient#refresh_credentials` was called: NoMethodError: undefined method 'config' for module OAuth2 This commit changes the require statements to just require `oauth2` which in turn [requires all the relevant files][2] in the `oauth2` gem. The require statement in `spec/rpi_auth/oauth_client_spec.rb` is unnecessary, because it's automatically loading `RpiAuth::OauthClient` which in turn loads `oauth2`. This should mean we no longer see exceptions like the one above. I've tested that this fix works in `experience-cs` in RaspberryPiFoundation/experience-cs#421 - I ran the Rails app and triggered a token refresh to check that `NoMethodError` was no longer being raised. [1]: https://raspberrypifoundation.sentry.io/issues/6590882516?project=4508953237651456 [2]: https://gitlab.com/oauth-xx/oauth2/-/blob/v2.0.9/lib/oauth2.rb?ref_type=tags#L11-23
2 parents 19a41f0 + 003dade commit 97e40f8

File tree

10 files changed

+16
-11
lines changed

10 files changed

+16
-11
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Removed
1515

16+
## [v4.1.1]
17+
18+
### Fixed
19+
20+
- Fix requiring of oauth2 to avoid `NoMethodError: undefined method 'config' for module OAuth2` (#86)
21+
1622
## [v4.1.0]
1723

1824
### Added
@@ -140,7 +146,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
140146
- rails model concern to allow host app to add auth behaviour to a model
141147
- callback, logout and failure routes to handle auth
142148

143-
[Unreleased]: https://github.com/RaspberryPiFoundation/rpi-auth/compare/v4.1.0...HEAD
149+
[Unreleased]: https://github.com/RaspberryPiFoundation/rpi-auth/compare/v4.1.1...HEAD
150+
[v4.1.1]: https://github.com/RaspberryPiFoundation/rpi-auth/releases/tag/v4.1.1
144151
[v4.1.0]: https://github.com/RaspberryPiFoundation/rpi-auth/releases/tag/v4.1.0
145152
[v4.0.0]: https://github.com/RaspberryPiFoundation/rpi-auth/releases/tag/v4.0.0
146153
[v3.6.0]: https://github.com/RaspberryPiFoundation/rpi-auth/releases/tag/v3.6.0

gemfiles/rails_6.1.gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ..
33
specs:
4-
rpi_auth (4.1.0)
4+
rpi_auth (4.1.1)
55
oauth2
66
omniauth-rails_csrf_protection (~> 1.0.0)
77
omniauth_openid_connect (~> 0.7.1)

gemfiles/rails_7.0.gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ..
33
specs:
4-
rpi_auth (4.1.0)
4+
rpi_auth (4.1.1)
55
oauth2
66
omniauth-rails_csrf_protection (~> 1.0.0)
77
omniauth_openid_connect (~> 0.7.1)

gemfiles/rails_7.1.gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ..
33
specs:
4-
rpi_auth (4.1.0)
4+
rpi_auth (4.1.1)
55
oauth2
66
omniauth-rails_csrf_protection (~> 1.0.0)
77
omniauth_openid_connect (~> 0.7.1)

gemfiles/rails_7.2.gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ..
33
specs:
4-
rpi_auth (4.1.0)
4+
rpi_auth (4.1.1)
55
oauth2
66
omniauth-rails_csrf_protection (~> 1.0.0)
77
omniauth_openid_connect (~> 0.7.1)

lib/rpi_auth/controllers/auto_refreshing_token.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require 'oauth2/error'
3+
require 'oauth2'
44

55
module RpiAuth
66
module Controllers

lib/rpi_auth/oauth_client.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

3-
require 'oauth2/client'
4-
require 'oauth2/access_token'
3+
require 'oauth2'
54

65
module RpiAuth
76
class OauthClient

lib/rpi_auth/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module RpiAuth
4-
VERSION = '4.1.0'
4+
VERSION = '4.1.1'
55
end

spec/dummy/spec/requests/refresh_credentials_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'spec_helper'
44

5-
require 'oauth2/error'
5+
require 'oauth2'
66

77
RSpec.describe 'Refreshing the auth token', type: :request do
88
include ActiveSupport::Testing::TimeHelpers

spec/rpi_auth/oauth_client_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require 'spec_helper'
4-
require 'oauth2'
54

65
RSpec.describe RpiAuth::OauthClient do
76
include ActiveSupport::Testing::TimeHelpers

0 commit comments

Comments
 (0)