Skip to content

Commit 8b4d6da

Browse files
davidtaylorhqzquestz
authored andcommitted
Ensure info[:email] is always verified, and include unverified_email (#363)
This is a 'safe by default' replacement for efe0e90 Add changelog and bump version Keep email_verified boolean available for 0.6.1 users
1 parent 2f6c464 commit 8b4d6da

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## 0.7.0 - 2019-06-03
5+
6+
### Added
7+
- Ensure `info[:email]` is always verified, and include `unverified_email`
8+
9+
### Deprecated
10+
- Nothing.
11+
12+
### Removed
13+
- Nothing.
14+
15+
### Fixed
16+
- Nothing.
17+
418
## 0.6.1 - 2019-03-07
519

620
### Added

lib/omniauth/google_oauth2/version.rb

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

33
module OmniAuth
44
module GoogleOauth2
5-
VERSION = '0.6.1'
5+
VERSION = '0.7.0'
66
end
77
end

lib/omniauth/strategies/google_oauth2.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def authorize_params
4646
info do
4747
prune!(
4848
name: raw_info['name'],
49-
email: raw_info['email'],
49+
email: verified_email,
50+
unverified_email: raw_info['email'],
5051
email_verified: raw_info['email_verified'],
5152
first_name: raw_info['given_name'],
5253
last_name: raw_info['family_name'],
@@ -137,6 +138,10 @@ def get_scope(params)
137138
scope_list.join(' ')
138139
end
139140

141+
def verified_email
142+
raw_info['email_verified'] ? raw_info['email'] : nil
143+
end
144+
140145
def get_token_options(redirect_uri)
141146
{ redirect_uri: redirect_uri }.merge(token_params.to_hash(symbolize_keys: true))
142147
end

spec/omniauth/strategies/google_oauth2_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,41 @@
300300
end
301301
end
302302

303+
describe '#info' do
304+
let(:client) do
305+
OAuth2::Client.new('abc', 'def') do |builder|
306+
builder.request :url_encoded
307+
builder.adapter :test do |stub|
308+
stub.get('/oauth2/v3/userinfo') { [200, { 'content-type' => 'application/json' }, response_hash.to_json] }
309+
end
310+
end
311+
end
312+
let(:access_token) { OAuth2::AccessToken.from_hash(client, {}) }
313+
before { allow(subject).to receive(:access_token).and_return(access_token) }
314+
315+
context 'with verified email' do
316+
let(:response_hash) do
317+
{ email: 'something@domain.invalid', email_verified: true }
318+
end
319+
320+
it 'should return equal email and unverified_email' do
321+
expect(subject.info[:email]).to eq('something@domain.invalid')
322+
expect(subject.info[:unverified_email]).to eq('something@domain.invalid')
323+
end
324+
end
325+
326+
context 'with unverified email' do
327+
let(:response_hash) do
328+
{ email: 'something@domain.invalid', email_verified: false }
329+
end
330+
331+
it 'should return nil email, and correct unverified email' do
332+
expect(subject.info[:email]).to eq(nil)
333+
expect(subject.info[:unverified_email]).to eq('something@domain.invalid')
334+
end
335+
end
336+
end
337+
303338
describe '#extra' do
304339
let(:client) do
305340
OAuth2::Client.new('abc', 'def') do |builder|

0 commit comments

Comments
 (0)