Skip to content

Commit

Permalink
Merge pull request #10 from RaspberryPiFoundation/add-username-to-str…
Browse files Browse the repository at this point in the history
…ategy

Add username to v0 strategy
  • Loading branch information
grega authored Jun 10, 2021
2 parents bc97917 + f980f35 commit 1353618
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,6 @@ use OmniAuth::Builder do
end
```

## Publishing changes

When publishing changes to the provider, don't forget to bump the version number in `lib/omniauth-rpi/version.rb`
2 changes: 1 addition & 1 deletion lib/omniauth-rpi/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OmniAuth
module Rpi
VERSION = '0.6.0'.freeze
VERSION = '0.7.0'.freeze
end
end
6 changes: 6 additions & 0 deletions lib/omniauth/strategies/hydra0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def callback_url
info do
{
'email' => email,
'username' => username,
'name' => fullname,
'nickname' => nickname,
'image' => image,
Expand All @@ -54,6 +55,11 @@ def email
raw_info['email']
end

# <13 accounts have username instead of email
def username
raw_info['username']
end

def nickname
raw_info['nickname']
end
Expand Down
3 changes: 3 additions & 0 deletions lib/rpi_auth_bypass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module RpiAuthBypass
DEFAULT_UID = 'b6301f34-b970-4d4f-8314-f877bad8b150'
DEFAULT_EMAIL = '[email protected]'
DEFAULT_USERNAME = 'webteam'
DEFAULT_NAME = 'Web Team'
DEFAULT_NICKNAME = 'Web'
DEFAULT_PROFILE = 'https://profile.raspberrypi.org/not/a/real/path'
Expand All @@ -15,6 +16,7 @@ module RpiAuthBypass
name: DEFAULT_NAME,
nickname: DEFAULT_NICKNAME,
email: DEFAULT_EMAIL,
username: DEFAULT_USERNAME,
image: DEFAULT_IMAGE,
}.freeze
DEFAULT_EXTRA = {
Expand All @@ -23,6 +25,7 @@ module RpiAuthBypass
name: DEFAULT_NAME,
nickname: DEFAULT_NICKNAME,
email: DEFAULT_EMAIL,
username: DEFAULT_USERNAME,
country: DEFAULT_COUNTRY,
country_code: DEFAULT_COUNTRY_CODE,
postcode: DEFAULT_POSTCODE,
Expand Down
16 changes: 15 additions & 1 deletion spec/rpi_auth_bypass_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
expect(subject.info.email).to eq(RpiAuthBypass::DEFAULT_EMAIL)
end

it 'has the default username' do
expect(subject.info.username).to eq(RpiAuthBypass::DEFAULT_USERNAME)
end

it 'has the default name' do
expect(subject.info.name).to eq(RpiAuthBypass::DEFAULT_NAME)
end
Expand Down Expand Up @@ -86,17 +90,19 @@
let(:name) { 'Robert Flemming' }
let(:nickname) { 'Bob' }
let(:email) { '[email protected]' }
let(:username) { 'bob.flemming' }
let(:roles) { 'gardener' }
let(:image) { 'https://my.avatar.com/image/1' }
let(:profile) { 'https://my.user.com/profile/1' }
let(:country) { 'United States' }
let(:country_code) { 'US' }
let(:postcode) { '123456' }

let(:info) { { name: name, email: email, nickname: nickname, image: image } }
let(:info) { { name: name, email: email, username: username, nickname: nickname, image: image } }
let(:extra) { { raw_info: {
name: name,
email: email,
username: username,
nickname: nickname,
roles: roles,
avatar: image,
Expand All @@ -115,6 +121,10 @@
expect(subject.info.email).to eq(email)
end

it 'has the username from info' do
expect(subject.info.username).to eq(username)
end

it 'has the name from info' do
expect(subject.info.name).to eq(name)
end
Expand All @@ -131,6 +141,10 @@
expect(subject.extra.raw_info.email).to eq(email)
end

it 'has the username from extra' do
expect(subject.extra.raw_info.username).to eq(username)
end

it 'has the name from extra' do
expect(subject.extra.raw_info.name).to eq(name)
end
Expand Down

0 comments on commit 1353618

Please sign in to comment.