Skip to content

Commit

Permalink
Ensure info[:email] is always verified, and include `unverified_ema…
Browse files Browse the repository at this point in the history
…il` (#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
  • Loading branch information
davidtaylorhq authored and zquestz committed Jun 3, 2019
1 parent 2f6c464 commit 8b4d6da
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# Changelog
All notable changes to this project will be documented in this file.

## 0.7.0 - 2019-06-03

### Added
- Ensure `info[:email]` is always verified, and include `unverified_email`

### Deprecated
- Nothing.

### Removed
- Nothing.

### Fixed
- Nothing.

## 0.6.1 - 2019-03-07

### Added
Expand Down
2 changes: 1 addition & 1 deletion lib/omniauth/google_oauth2/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module OmniAuth
module GoogleOauth2
VERSION = '0.6.1'
VERSION = '0.7.0'
end
end
7 changes: 6 additions & 1 deletion lib/omniauth/strategies/google_oauth2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def authorize_params
info do
prune!(
name: raw_info['name'],
email: raw_info['email'],
email: verified_email,
unverified_email: raw_info['email'],
email_verified: raw_info['email_verified'],
first_name: raw_info['given_name'],
last_name: raw_info['family_name'],
Expand Down Expand Up @@ -137,6 +138,10 @@ def get_scope(params)
scope_list.join(' ')
end

def verified_email
raw_info['email_verified'] ? raw_info['email'] : nil
end

def get_token_options(redirect_uri)
{ redirect_uri: redirect_uri }.merge(token_params.to_hash(symbolize_keys: true))
end
Expand Down
35 changes: 35 additions & 0 deletions spec/omniauth/strategies/google_oauth2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,41 @@
end
end

describe '#info' do
let(:client) do
OAuth2::Client.new('abc', 'def') do |builder|
builder.request :url_encoded
builder.adapter :test do |stub|
stub.get('/oauth2/v3/userinfo') { [200, { 'content-type' => 'application/json' }, response_hash.to_json] }
end
end
end
let(:access_token) { OAuth2::AccessToken.from_hash(client, {}) }
before { allow(subject).to receive(:access_token).and_return(access_token) }

context 'with verified email' do
let(:response_hash) do
{ email: '[email protected]', email_verified: true }
end

it 'should return equal email and unverified_email' do
expect(subject.info[:email]).to eq('[email protected]')
expect(subject.info[:unverified_email]).to eq('[email protected]')
end
end

context 'with unverified email' do
let(:response_hash) do
{ email: '[email protected]', email_verified: false }
end

it 'should return nil email, and correct unverified email' do
expect(subject.info[:email]).to eq(nil)
expect(subject.info[:unverified_email]).to eq('[email protected]')
end
end
end

describe '#extra' do
let(:client) do
OAuth2::Client.new('abc', 'def') do |builder|
Expand Down

0 comments on commit 8b4d6da

Please sign in to comment.