Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
Gemspec/DevelopmentDependencies:
Exclude:
- 'rpi_auth.gemspec'
- "rpi_auth.gemspec"

# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Expand Down Expand Up @@ -43,4 +43,5 @@ RSpec/NestedGroups:
# Include: **/*_spec.rb
RSpec/SpecFilePathFormat:
Exclude:
- 'spec/rpi_auth/models/authenticatable_spec.rb'
- "spec/rpi_auth/models/authenticatable_spec.rb"
- "spec/rpi_auth/models/with_tokens_spec.rb"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- Add access token-related functionality including auto-refresh (#83)

### Fixed
- Fix use of `User#expires_at` in `SpecHelpers#stub_auth_for` (#82)
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,29 @@ class in `config/application.rb`.
config.railties_order = [RpiAuth::Engine, :main_app, :all]
```

### Obtaining an access token for user

This optional behaviour is useful if your Rails app (which is using this gem)
needs to use a RPF API which required authentication via an OAuth2 access
token.

Include the `RpiAuth::Models::WithTokens` concern (which depends on the
`RpiAuth::Models::Authenticatable` concern) into your user model in order to
add `access_token`, `refresh_token` & `expires_at` attributes. These methods
are automatically populated by `RpiAuth::AuthController#callback` via the
`RpiAuth::Models::WithTokens.from_omniauth` method.

This also relies on the following:
- `RpiAuth.configuration.scope` including the "offline" scope in the Rails app
which is using the `rpi_auth` gem.
- In the `profile` app `hydra_client` config for the Rails app, `grant_types`
must include "refresh_token" and `scope` must include "offline".

Include the `RpiAuth::Controllers::AutoRefreshingToken` concern (which depends
on the `RpiAuth::Controllers::CurrentUser` concern) into your controller so
that when the user's access token expires, a new one is obtained using the
user's refresh token.

## Test helpers and routes

There are some standardised test helpers in `RpiAuth::SpecHelpers` that can be used when testing.
Expand Down
27 changes: 27 additions & 0 deletions gemfiles/rails_6.1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PATH
remote: ..
specs:
rpi_auth (4.0.0)
oauth2
omniauth-rails_csrf_protection (~> 1.0.0)
omniauth_openid_connect (~> 0.7.1)
rails (>= 6.1.4)
Expand Down Expand Up @@ -74,6 +75,7 @@ GEM
ast (2.4.3)
attr_required (1.0.2)
base64 (0.2.0)
bigdecimal (3.1.9)
bindata (2.5.1)
builder (3.3.0)
byebug (12.0.0)
Expand All @@ -88,6 +90,9 @@ GEM
xpath (~> 3.2)
coderay (1.1.3)
concurrent-ruby (1.3.5)
crack (1.0.0)
bigdecimal
rexml
crass (1.0.6)
date (3.4.1)
diff-lcs (1.6.1)
Expand All @@ -106,6 +111,7 @@ GEM
ffi (1.17.1)
globalid (1.2.1)
activesupport (>= 6.1)
hashdiff (1.1.2)
hashie (5.0.0)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
Expand All @@ -117,6 +123,8 @@ GEM
bindata
faraday (~> 2.0)
faraday-follow_redirects
jwt (2.10.1)
base64
language_server-protocol (3.17.0.4)
lint_roller (1.1.0)
listen (3.9.0)
Expand All @@ -137,6 +145,8 @@ GEM
mini_mime (1.1.5)
mini_portile2 (2.8.8)
minitest (5.25.5)
multi_xml (0.7.1)
bigdecimal (~> 3.1)
net-http (0.6.0)
uri
net-imap (0.5.6)
Expand All @@ -152,6 +162,13 @@ GEM
nokogiri (1.18.7)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
oauth2 (2.0.9)
faraday (>= 0.17.3, < 3.0)
jwt (>= 1.0, < 3.0)
multi_xml (~> 0.5)
rack (>= 1.2, < 4)
snaky_hash (~> 2.0)
version_gem (~> 1.1)
omniauth (2.1.3)
hashie (>= 3.4.6)
rack (>= 2.2.3)
Expand Down Expand Up @@ -237,6 +254,7 @@ GEM
rb-inotify (0.11.1)
ffi (~> 1.0)
regexp_parser (2.10.0)
rexml (3.4.1)
rspec-core (3.13.3)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
Expand Down Expand Up @@ -290,6 +308,9 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
snaky_hash (2.0.1)
hashie
version_gem (~> 1.1, >= 1.1.1)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand All @@ -313,10 +334,15 @@ GEM
validate_url (1.0.15)
activemodel (>= 3.0.0)
public_suffix
version_gem (1.1.7)
webfinger (2.1.3)
activesupport
faraday (~> 2.0)
faraday-follow_redirects
webmock (3.25.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
websocket-driver (0.7.7)
base64
websocket-extensions (>= 0.1.0)
Expand All @@ -342,6 +368,7 @@ DEPENDENCIES
rubocop-rails
rubocop-rspec
simplecov
webmock

BUNDLED WITH
2.3.27
27 changes: 27 additions & 0 deletions gemfiles/rails_7.0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PATH
remote: ..
specs:
rpi_auth (4.0.0)
oauth2
omniauth-rails_csrf_protection (~> 1.0.0)
omniauth_openid_connect (~> 0.7.1)
rails (>= 6.1.4)
Expand Down Expand Up @@ -80,6 +81,7 @@ GEM
ast (2.4.3)
attr_required (1.0.2)
base64 (0.2.0)
bigdecimal (3.1.9)
bindata (2.5.1)
builder (3.3.0)
byebug (12.0.0)
Expand All @@ -94,6 +96,9 @@ GEM
xpath (~> 3.2)
coderay (1.1.3)
concurrent-ruby (1.3.5)
crack (1.0.0)
bigdecimal
rexml
crass (1.0.6)
date (3.4.1)
diff-lcs (1.6.1)
Expand All @@ -112,6 +117,7 @@ GEM
ffi (1.17.1)
globalid (1.2.1)
activesupport (>= 6.1)
hashdiff (1.1.2)
hashie (5.0.0)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
Expand All @@ -123,6 +129,8 @@ GEM
bindata
faraday (~> 2.0)
faraday-follow_redirects
jwt (2.10.1)
base64
language_server-protocol (3.17.0.4)
lint_roller (1.1.0)
listen (3.9.0)
Expand All @@ -143,6 +151,8 @@ GEM
mini_mime (1.1.5)
mini_portile2 (2.8.8)
minitest (5.25.5)
multi_xml (0.7.1)
bigdecimal (~> 3.1)
net-http (0.6.0)
uri
net-imap (0.5.6)
Expand All @@ -158,6 +168,13 @@ GEM
nokogiri (1.18.7)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
oauth2 (2.0.9)
faraday (>= 0.17.3, < 3.0)
jwt (>= 1.0, < 3.0)
multi_xml (~> 0.5)
rack (>= 1.2, < 4)
snaky_hash (~> 2.0)
version_gem (~> 1.1)
omniauth (2.1.3)
hashie (>= 3.4.6)
rack (>= 2.2.3)
Expand Down Expand Up @@ -243,6 +260,7 @@ GEM
rb-inotify (0.11.1)
ffi (~> 1.0)
regexp_parser (2.10.0)
rexml (3.4.1)
rspec-core (3.13.3)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
Expand Down Expand Up @@ -296,6 +314,9 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
snaky_hash (2.0.1)
hashie
version_gem (~> 1.1, >= 1.1.1)
swd (2.0.3)
activesupport (>= 3)
attr_required (>= 0.0.5)
Expand All @@ -312,10 +333,15 @@ GEM
validate_url (1.0.15)
activemodel (>= 3.0.0)
public_suffix
version_gem (1.1.7)
webfinger (2.1.3)
activesupport
faraday (~> 2.0)
faraday-follow_redirects
webmock (3.25.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
websocket-driver (0.7.7)
base64
websocket-extensions (>= 0.1.0)
Expand All @@ -341,6 +367,7 @@ DEPENDENCIES
rubocop-rails
rubocop-rspec
simplecov
webmock

BUNDLED WITH
2.3.27
26 changes: 26 additions & 0 deletions gemfiles/rails_7.1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PATH
remote: ..
specs:
rpi_auth (4.0.0)
oauth2
omniauth-rails_csrf_protection (~> 1.0.0)
omniauth_openid_connect (~> 0.7.1)
rails (>= 6.1.4)
Expand Down Expand Up @@ -109,6 +110,9 @@ GEM
coderay (1.1.3)
concurrent-ruby (1.3.5)
connection_pool (2.5.0)
crack (1.0.0)
bigdecimal
rexml
crass (1.0.6)
date (3.4.1)
diff-lcs (1.6.1)
Expand All @@ -128,6 +132,7 @@ GEM
ffi (1.17.1)
globalid (1.2.1)
activesupport (>= 6.1)
hashdiff (1.1.2)
hashie (5.0.0)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
Expand All @@ -144,6 +149,8 @@ GEM
bindata
faraday (~> 2.0)
faraday-follow_redirects
jwt (2.10.1)
base64
language_server-protocol (3.17.0.4)
lint_roller (1.1.0)
listen (3.9.0)
Expand All @@ -164,6 +171,8 @@ GEM
mini_mime (1.1.5)
mini_portile2 (2.8.8)
minitest (5.25.5)
multi_xml (0.7.1)
bigdecimal (~> 3.1)
mutex_m (0.3.0)
net-http (0.6.0)
uri
Expand All @@ -180,6 +189,13 @@ GEM
nokogiri (1.18.7)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
oauth2 (2.0.9)
faraday (>= 0.17.3, < 3.0)
jwt (>= 1.0, < 3.0)
multi_xml (~> 0.5)
rack (>= 1.2, < 4)
snaky_hash (~> 2.0)
version_gem (~> 1.1)
omniauth (2.1.3)
hashie (>= 3.4.6)
rack (>= 2.2.3)
Expand Down Expand Up @@ -282,6 +298,7 @@ GEM
regexp_parser (2.10.0)
reline (0.6.1)
io-console (~> 0.5)
rexml (3.4.1)
rspec-core (3.13.3)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
Expand Down Expand Up @@ -336,6 +353,9 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
snaky_hash (2.0.1)
hashie
version_gem (~> 1.1, >= 1.1.1)
stringio (3.1.6)
swd (2.0.3)
activesupport (>= 3)
Expand All @@ -353,10 +373,15 @@ GEM
validate_url (1.0.15)
activemodel (>= 3.0.0)
public_suffix
version_gem (1.1.7)
webfinger (2.1.3)
activesupport
faraday (~> 2.0)
faraday-follow_redirects
webmock (3.25.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
websocket-driver (0.7.7)
base64
websocket-extensions (>= 0.1.0)
Expand All @@ -382,6 +407,7 @@ DEPENDENCIES
rubocop-rails
rubocop-rspec
simplecov
webmock

BUNDLED WITH
2.3.27
Loading