omniauth-rpi 1.1.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +87 -36
- data/lib/omniauth/strategies/hydra1.rb +3 -3
- data/lib/omniauth-rpi/version.rb +1 -1
- data/lib/omniauth-rpi.rb +0 -1
- metadata +5 -6
- data/lib/omniauth/strategies/hydra0.rb +0 -79
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cac46043e419722d2bc271fe0c7f1c2598564e9152c1924276375f975bf0245a
|
4
|
+
data.tar.gz: e6bd7a55d9733ad063e0ade779e7fd9d4e8ac761040b788e7a0896e5fb2f3ff0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f75ab8d0e83b4cfad930614611472151c0db44409819f6cc11b6990a3384a4dc36e9337fe82e7bcc50eb6b6007c44952f8e3820dd287319c4988b6ec5878acf8
|
7
|
+
data.tar.gz: e61a9bcaa2df572b40006a1ecac62620d035b9f49e9f05410fe0b8baab5bd74b6d08a8f53a5bbf08165024aae6f21587bfbd8c426630e503c7b96638bf11772b
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [1.3.2] - 2023-02-02
|
8
|
+
### Changed
|
9
|
+
- Fixes setting of uid from raw_info (uid was previously blank)
|
10
|
+
|
11
|
+
## [1.3.1] - 2021-10-14
|
12
|
+
### Changed
|
13
|
+
- Removed Hydra v0 strategy, which is better handled in the `hydra-v0` branch and `v0.x.x` releases
|
14
|
+
|
15
|
+
## [1.3.0] - 2021-10-14
|
16
|
+
### Changed
|
17
|
+
- Replaced force_signup param with a more extensible login_options param
|
18
|
+
|
19
|
+
## [1.2.0] - 2021-09-30
|
20
|
+
### Added
|
21
|
+
- Added force_signup param to enable passing of custom param to the identity provider
|
22
|
+
|
7
23
|
## [1.1.0] - 2021-09-10
|
8
24
|
### Added
|
9
25
|
- Changelog in preparation for publishing app to rubygems.org
|
data/README.md
CHANGED
@@ -1,87 +1,138 @@
|
|
1
1
|
# OmniAuth Raspberry Pi
|
2
2
|
|
3
|
-
This is the official OmniAuth strategy for authenticating to Raspberry
|
3
|
+
This is the official OmniAuth strategy for authenticating to Raspberry Pi Accounts using Hydra v1 (for Hydra v0 see the `hydra-v0` branch and `v0.x.x` releases).
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'omniauth-rpi',
|
10
|
+
gem 'omniauth-rpi',
|
11
|
+
git: 'https://github.com/RaspberryPiFoundation/omniauth-rpi.git',
|
12
|
+
tag: 'v1.3.2'
|
11
13
|
```
|
12
14
|
|
13
15
|
And then execute:
|
14
16
|
|
15
17
|
$ bundle
|
16
18
|
|
17
|
-
##
|
19
|
+
## Usage with OmniAuth
|
18
20
|
|
19
21
|
- [Integrating with OmniAuth](https://github.com/omniauth/omniauth/wiki)
|
20
|
-
- [Integrating with Devise](https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview)
|
21
22
|
|
23
|
+
In `config/initializers/omniauth.rb`:
|
22
24
|
|
23
25
|
```ruby
|
24
|
-
|
25
|
-
|
26
|
+
OmniAuth.config.logger = Rails.logger
|
27
|
+
|
28
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
29
|
+
provider(
|
30
|
+
OmniAuth::Strategies::Rpi, ENV['AUTH_CLIENT_ID'], ENV['AUTH_CLIENT_SECRET'],
|
31
|
+
scope: 'openid email profile force-consent',
|
32
|
+
callback_path: '/auth/callback',
|
33
|
+
client_options: {
|
34
|
+
site: ENV['AUTH_URL'],
|
35
|
+
authorize_url: "#{ENV['AUTH_URL']}/oauth2/auth",
|
36
|
+
token_url: "#{ENV['AUTH_URL']}/oauth2/token"
|
37
|
+
},
|
38
|
+
authorize_params: {
|
39
|
+
brand: '<brand>'
|
40
|
+
}
|
41
|
+
)
|
42
|
+
|
43
|
+
OmniAuth.config.on_failure = AuthController.action(:failure)
|
26
44
|
end
|
27
45
|
```
|
28
46
|
|
47
|
+
(the `Rpi` strategy extends the `Hydra1` strategy)
|
48
|
+
|
49
|
+
## Usage with Devise
|
50
|
+
|
51
|
+
- [Integrating with Devise](https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview)
|
52
|
+
|
29
53
|
## Use in development
|
30
54
|
|
31
55
|
In development it is sometimes useful to point at a staging/local version of the authentication
|
32
|
-
server (ie Hydra).
|
56
|
+
server (ie. Hydra).
|
33
57
|
|
34
58
|
```ruby
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
:authorize_url => 'http://localhost:9000/oauth2/auth',
|
41
|
-
:token_url => 'http://localhost:9000/oauth2/token'
|
42
|
-
}
|
43
|
-
)
|
59
|
+
:client_options => {
|
60
|
+
:site => 'http://localhost:9000',
|
61
|
+
:authorize_url => 'http://localhost:9000/oauth2/auth',
|
62
|
+
:token_url => 'http://localhost:9000/oauth2/token'
|
63
|
+
}
|
44
64
|
```
|
45
65
|
|
46
66
|
## Bypassing OmniAuth/OAuth
|
47
67
|
|
48
|
-
It is also possible to bypass OmniAuth (and OAuth)
|
68
|
+
It is also possible to bypass OmniAuth (and OAuth) entirely which can be useful in circumstances where hostnames are dynamic, e.g. in review deployments, as well as in development. To do this add the following code to your OmniAuth initializer:
|
49
69
|
|
50
70
|
```ruby
|
51
|
-
#
|
52
|
-
|
53
|
-
if ENV.has_key? 'BYPASS_OAUTH'
|
71
|
+
# Use an environment variable set outside the app to trigger the auth bypass
|
72
|
+
if ENV['BYPASS_OAUTH'].present?
|
54
73
|
using RpiAuthBypass
|
55
74
|
OmniAuth.config.enable_rpi_auth_bypass
|
56
75
|
end
|
57
76
|
```
|
58
77
|
|
59
78
|
This will log you in with the following details:
|
60
|
-
*
|
79
|
+
* uuid: `b6301f34-b970-4d4f-8314-f877bad8b150`
|
61
80
|
* email: `web@raspberrypi.org`
|
62
81
|
* name: `Web Team`
|
63
82
|
* nickname: `Web`
|
64
83
|
|
65
|
-
If you wish to specify your user's details, you can add the info manually
|
84
|
+
If you wish to specify your user's details, you can add the info manually:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
if ENV['BYPASS_OAUTH'].present?
|
88
|
+
using RpiAuthBypass
|
89
|
+
OmniAuth.config.add_rpi_mock(
|
90
|
+
uid: 'b6301f34-b970-4d4f-8314-f877bad8b150',
|
91
|
+
info: {
|
92
|
+
email: 'web@raspberrypi.org',
|
93
|
+
name: 'Digital Products Team',
|
94
|
+
nickname: 'DP',
|
95
|
+
image: 'https://static.raspberrypi.org/files/accounts/default-avatar.jpg'
|
96
|
+
},
|
97
|
+
extra: {
|
98
|
+
raw_info: {
|
99
|
+
name: 'Digital Products Team',
|
100
|
+
nickname: 'DP',
|
101
|
+
email: 'web@raspberrypi.org',
|
102
|
+
country: 'United Kingdom',
|
103
|
+
country_code: 'GB',
|
104
|
+
postcode: 'CB1 1AA',
|
105
|
+
picture: 'https://static.raspberrypi.org/files/accounts/default-avatar.jpg',
|
106
|
+
profile: 'https://my.raspberrypi.org/not/a/real/path'
|
107
|
+
}
|
108
|
+
}
|
109
|
+
)
|
110
|
+
OmniAuth.config.enable_rpi_auth_bypass
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
114
|
+
## Forcing sign up flow
|
115
|
+
|
116
|
+
It's possible to force a redirect to the Pi Accounts sign up page (rather than the default log in page) through:
|
117
|
+
|
66
118
|
```
|
67
|
-
|
119
|
+
POST /auth/rpi?login_options=force_signup
|
68
120
|
```
|
69
121
|
|
70
|
-
|
122
|
+
For the full documentation see: https://github.com/RaspberryPiFoundation/documentation/blob/main/accounts/force-signup.md
|
123
|
+
|
124
|
+
## Testing
|
125
|
+
|
126
|
+
Run:
|
71
127
|
|
72
|
-
```
|
73
|
-
|
74
|
-
|
75
|
-
use OmniAuth::Builder do
|
76
|
-
configure do |c|
|
77
|
-
if ENV.has_key? 'BYPASS_OAUTH'
|
78
|
-
c.enable_rpi_auth_bypass
|
79
|
-
c.add_rpi_mock(uid: 'foo', info: {name: ... } )
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
128
|
+
```
|
129
|
+
rspec
|
83
130
|
```
|
84
131
|
|
85
132
|
## Publishing changes
|
86
133
|
|
87
|
-
|
134
|
+
https://rubygems.org/gems/omniauth-rpi
|
135
|
+
|
136
|
+
When publishing changes to the provider, don't forget to bump the version number in `lib/omniauth-rpi/version.rb` and update `CHANGELOG.md` accordingly.
|
137
|
+
|
138
|
+
How to publish to Rubygems: https://guides.rubygems.org/publishing/#publishing-to-rubygemsorg
|
@@ -11,10 +11,10 @@ module OmniAuth
|
|
11
11
|
authorize_url:'https://auth-v1.raspberrypi.org/oauth2/auth',
|
12
12
|
token_url: 'https://auth-v1.raspberrypi.org/oauth2/token'
|
13
13
|
}
|
14
|
-
|
14
|
+
|
15
15
|
def authorize_params
|
16
16
|
super.tap do |params|
|
17
|
-
%w[scope client_options].each do |v|
|
17
|
+
%w[scope client_options login_options].each do |v|
|
18
18
|
params[v.to_sym] = request.params[v] if request.params[v]
|
19
19
|
end
|
20
20
|
end
|
@@ -24,7 +24,7 @@ module OmniAuth
|
|
24
24
|
full_host + callback_path
|
25
25
|
end
|
26
26
|
|
27
|
-
uid { raw_info['
|
27
|
+
uid { raw_info['uuid'].to_s }
|
28
28
|
|
29
29
|
info do
|
30
30
|
{
|
data/lib/omniauth-rpi/version.rb
CHANGED
data/lib/omniauth-rpi.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-rpi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raspberry Pi Foundation
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|
@@ -159,7 +159,6 @@ files:
|
|
159
159
|
- bin/setup
|
160
160
|
- lib/omniauth-rpi.rb
|
161
161
|
- lib/omniauth-rpi/version.rb
|
162
|
-
- lib/omniauth/strategies/hydra0.rb
|
163
162
|
- lib/omniauth/strategies/hydra1.rb
|
164
163
|
- lib/omniauth/strategies/rpi.rb
|
165
164
|
- lib/rpi_auth_bypass.rb
|
@@ -168,7 +167,7 @@ homepage: https://www.raspberrypi.org
|
|
168
167
|
licenses:
|
169
168
|
- MIT
|
170
169
|
metadata: {}
|
171
|
-
post_install_message:
|
170
|
+
post_install_message:
|
172
171
|
rdoc_options: []
|
173
172
|
require_paths:
|
174
173
|
- lib
|
@@ -184,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
183
|
version: '0'
|
185
184
|
requirements: []
|
186
185
|
rubygems_version: 3.1.4
|
187
|
-
signing_key:
|
186
|
+
signing_key:
|
188
187
|
specification_version: 4
|
189
188
|
summary: Official OmniAuth strategy for Raspberry Pi.
|
190
189
|
test_files: []
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'omniauth-oauth2'
|
2
|
-
require 'jwt'
|
3
|
-
|
4
|
-
module OmniAuth::Strategies
|
5
|
-
class Hydra0 < OmniAuth::Strategies::OAuth2
|
6
|
-
option :client_options,
|
7
|
-
:site => 'https://auth.raspberrypi.org',
|
8
|
-
:authorize_url => 'https://auth.raspberrypi.org/oauth2/auth',
|
9
|
-
:token_url => 'https://auth.raspberrypi.org/oauth2/token'
|
10
|
-
|
11
|
-
def authorize_params
|
12
|
-
super.tap do |params|
|
13
|
-
%w[scope client_options].each do |v|
|
14
|
-
params[v.to_sym] = request.params[v] if request.params[v]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def build_access_token
|
20
|
-
options.token_params[:headers] = { 'Authorization' => basic_auth_header }
|
21
|
-
super
|
22
|
-
end
|
23
|
-
|
24
|
-
def basic_auth_header
|
25
|
-
'Basic ' + Base64.strict_encode64("#{options[:client_id]}:#{options[:client_secret]}")
|
26
|
-
end
|
27
|
-
|
28
|
-
def callback_url
|
29
|
-
full_host + callback_path
|
30
|
-
end
|
31
|
-
|
32
|
-
uid { raw_info['uuid'].to_s }
|
33
|
-
|
34
|
-
info do
|
35
|
-
{
|
36
|
-
'email' => email,
|
37
|
-
'username' => username,
|
38
|
-
'name' => fullname,
|
39
|
-
'nickname' => nickname,
|
40
|
-
'image' => image,
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
|
-
extra do
|
45
|
-
{
|
46
|
-
'raw_info' => raw_info
|
47
|
-
}
|
48
|
-
end
|
49
|
-
|
50
|
-
def raw_info
|
51
|
-
@raw_info ||= (JWT.decode access_token.params['id_token'], nil, false)[0]
|
52
|
-
end
|
53
|
-
|
54
|
-
def email
|
55
|
-
raw_info['email']
|
56
|
-
end
|
57
|
-
|
58
|
-
# <13 accounts have username instead of email
|
59
|
-
def username
|
60
|
-
raw_info['username']
|
61
|
-
end
|
62
|
-
|
63
|
-
def nickname
|
64
|
-
raw_info['nickname']
|
65
|
-
end
|
66
|
-
|
67
|
-
# use fullname to avoid clash with 'name'
|
68
|
-
def fullname
|
69
|
-
raw_info['name']
|
70
|
-
end
|
71
|
-
|
72
|
-
def image
|
73
|
-
# deserialise openid claim into auth schema
|
74
|
-
raw_info['picture']
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
OmniAuth.config.add_camelization 'hydra0', 'Hydra0'
|