From 594494066e079f7cc8d012efc4f52aa217cd6f8a Mon Sep 17 00:00:00 2001 From: Sebastian Zaremba <1636476+vassyz@users.noreply.github.com> Date: Thu, 15 Mar 2018 13:24:20 +0100 Subject: [PATCH] SDK-273 v1.2.0 (#3) * [SDK-273]: Update strategy and bump version * [SDK-273]: Update strategy and bump version * [SDK-273]: Add minor tweaks --- CHANGELOG.md | 26 ++++--- README.md | 53 ++++++++++----- lib/omniauth/strategies/yoti.rb | 28 ++++++-- lib/omniauth/yoti/version.rb | 2 +- omniauth-yoti.gemspec | 6 +- rubocop.yml | 7 +- spec/omniauth/strategies/yoti_spec.rb | 98 +++++++++++++++------------ spec/spec_helper.rb | 2 +- 8 files changed, 136 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a88b24c..49b1e4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,23 @@ -# Change Log +# Changelog All notable changes to this project will be documented in this file. -The format is based on [Keep a Changelog](http://keepachangelog.com/) -and this project adheres to [Semantic Versioning](http://semver.org/). +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## 1.1.3 - 2017-11-01 +## [1.2.0] - 2018-03-09 +### Added +- `age_verified` returns a boolean value of the age validation + +### Changed +- Moved the profile attributes in the response Hash from `extra` to `info`. Please check [README.md](README.md#upgrading-from-version-11) for details. +## [1.1.3] - 2017-11-01 ### Added - `base64_selfie_uri` value -## 1.1.2 - 2017-10-18 +## [1.1.2] - 2017-10-18 -## 1.1.1 - 2017-09-13 +## [1.1.1] - 2017-09-13 ### Changed - Switched from proprietary to MIT license @@ -21,8 +27,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - `simplecov` `~> 0.15` - `webmock` `~> 3.0` -## 1.1.0 - 2017-04-11 -Updates dependencies to the latest versions and aligns extra fields naming conventions with the Yoti attributes. +## [1.1.0] - 2017-04-11 +Updated dependencies to the latest versions and aligns extra fields naming conventions with the Yoti attributes. ### Added - `email_address` field @@ -40,10 +46,10 @@ Updates dependencies to the latest versions and aligns extra fields naming conve - `simplecov` `~> 0.14` - `webmock` `~> 2.3` -## 1.0.1 - 2016-11-28 +## [1.0.1] - 2016-11-28 ### Added - Yoti proprietary license -## 1.0.0 - 2016-11-25 +## [1.0.0] - 2016-11-25 ### Added - This is an initial public release. diff --git a/README.md b/README.md index 0557ea9..c2d83b7 100644 --- a/README.md +++ b/README.md @@ -19,13 +19,13 @@ gem 'omniauth-yoti' And then execute: ```shell -$ bundle +bundle ``` Or install it yourself as: ```shell -$ gem install omniauth-yoti +gem install omniauth-yoti ``` ## Configuration @@ -63,21 +63,42 @@ A call to `/auth/yoti/callback` will open the Yoti authentication page, and afte "provider" => "yoti", "uid" => "mHvpV4...", "info" => { - "name" => "mHvpV4Mm+yMb...", - "base64_selfie_uri" => "data:image/jpeg;base64,/9j/2wCEAAMCAg..." - }, + "name" => "John Doe", + "selfie" => "jpeg image data file", + "full_name" => "John Doe", + "given_names" => "John", + "family_name" => "Doe", + "phone_number" => "07474747474", + "email_address" => "email@example.com", + "date_of_birth" => "1989-11-09", + "postal_address" => "Fountain House\n130 Fenchurch St\nLONDON\nEC3M 5DJ", + "gender" => "MALE", + "nationality" => "GBR" + "base64_selfie_uri" => "data:image/jpeg;base64,/9j/2wCEAAMCAg..." + "age_verified" => true + }, "credentials" => {}, "extra" => { - "selfie" => "jpeg image file", - "given_names" => "Given Name", - "family_name" => "Family Name", - "phone_number" => "07474747474", - "email_address" => "email@example.com", - "date_of_birth" => nil, - "postal_address" => nil, - "gender" => 'MALE', - "nationality" => nil - } + { "raw_info" => + { + "selfie" => "jpeg image data file", + "full_name" => "John Doe", + "given_names" => "Given Name", + "family_name" => "Family Name", + "phone_number" => "07474747474", + "email_address" => "email@example.com", + "date_of_birth" => "1989-11-09", + "postal_address" => "Fountain House\n130 Fenchurch St\nLONDON\nEC3M 5DJ", + "gender" => "MALE", + "nationality" => "GBR", + "age_over:18" => true + } + } } - ``` + +## Upgrading from version 1.1 + +Most of the profile attributes that were being stored in the `extra` fields got moved to `info`. + +e.g. `request.env['omniauth.auth']['extra']['given_names']` will become `request.env['omniauth.auth']['info']['given_names']` diff --git a/lib/omniauth/strategies/yoti.rb b/lib/omniauth/strategies/yoti.rb index 74c140c..8e65119 100644 --- a/lib/omniauth/strategies/yoti.rb +++ b/lib/omniauth/strategies/yoti.rb @@ -13,14 +13,12 @@ def request_phase end uid { yoti_user_id } - info {{ - name: yoti_user_id, - base64_selfie_uri: base64_selfie_uri - }} - def extra - @raw_info ||= { + info do + { + name: yoti_user_profile['full_name'], selfie: yoti_user_profile['selfie'], + full_name: yoti_user_profile['full_name'], given_names: yoti_user_profile['given_names'], family_name: yoti_user_profile['family_name'], phone_number: yoti_user_profile['phone_number'], @@ -28,10 +26,22 @@ def extra date_of_birth: yoti_user_profile['date_of_birth'], postal_address: yoti_user_profile['postal_address'], gender: yoti_user_profile['gender'], - nationality: yoti_user_profile['nationality'] + nationality: yoti_user_profile['nationality'], + base64_selfie_uri: base64_selfie_uri, + age_verified: age_verified } end + extra do + { + raw_info: raw_info + } + end + + def raw_info + @raw_info ||= yoti_user_profile + end + private def yoti_activity_details @@ -53,6 +63,10 @@ def base64_selfie_uri yoti_activity_details.base64_selfie_uri end + def age_verified + yoti_activity_details.age_verified + end + def configure_yoti_client! ::Yoti.configure do |config| config.client_sdk_id = options.client_options[:client_sdk_id] diff --git a/lib/omniauth/yoti/version.rb b/lib/omniauth/yoti/version.rb index 58f21f1..bbf13f9 100644 --- a/lib/omniauth/yoti/version.rb +++ b/lib/omniauth/yoti/version.rb @@ -1,5 +1,5 @@ module Omniauth module Yoti - VERSION = '1.1.3'.freeze + VERSION = '1.2.0'.freeze end end diff --git a/omniauth-yoti.gemspec b/omniauth-yoti.gemspec index ac3d024..92ad2a0 100644 --- a/omniauth-yoti.gemspec +++ b/omniauth-yoti.gemspec @@ -1,6 +1,4 @@ -# coding: utf-8 - -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'omniauth/yoti/version' @@ -22,7 +20,7 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 2.1.9' spec.add_dependency 'omniauth', '~> 1.6' - spec.add_dependency 'yoti', '~> 1.1.0' + spec.add_dependency 'yoti', '~> 1.2.1' spec.add_development_dependency 'bundler', '~> 1.13' spec.add_development_dependency 'rake', '~> 12.1' diff --git a/rubocop.yml b/rubocop.yml index bd1a720..104c654 100644 --- a/rubocop.yml +++ b/rubocop.yml @@ -1,7 +1,7 @@ AllCops: DisplayCopNames: true DisplayStyleGuide: true - TargetRubyVersion: 2.3 + TargetRubyVersion: 2.1.9 Metrics/AbcSize: Max: 20 @@ -13,6 +13,9 @@ Metrics/MethodLength: CountComments: false Max: 15 +Metrics/BlockLength: + Enabled: false + Style/Documentation: Enabled: false @@ -22,5 +25,5 @@ Style/FrozenStringLiteralComment: Style/NumericLiterals: Enabled: false -Style/FileName: +Naming: Enabled: false diff --git a/spec/omniauth/strategies/yoti_spec.rb b/spec/omniauth/strategies/yoti_spec.rb index 3420ea6..2ec7f82 100644 --- a/spec/omniauth/strategies/yoti_spec.rb +++ b/spec/omniauth/strategies/yoti_spec.rb @@ -46,13 +46,35 @@ end describe '#info' do - it 'returns the name value' do - expect(subject.info[:name]).to eql('Hig2yAT79cWvseSuXcIuCLa5lNkAPy70rxetUaeHlTJGmiwc/g1MWdYWYrexWvPU') + context 'when using a mock request' do + it 'returns the base64_selfie_uri value' do + selfie = File.read('spec/fixtures/selfie.txt', encoding: 'utf-8') + expect(subject.info[:base64_selfie_uri]).to eql(selfie) + end end - it 'returns the base64_selfie_uri value' do - selfie = File.read('spec/fixtures/selfie.txt', encoding: 'utf-8') - expect(subject.info[:base64_selfie_uri]).to eql(selfie) + context 'when using a mock object' do + before do + allow(subject).to receive(:yoti_user_profile).and_return(yoti_user_profile_mock) + allow(subject).to receive(:base64_selfie_uri).and_return(base64_selfie_uri_mock) + allow(subject).to receive(:age_verified).and_return(age_verified_mock) + end + + it 'returns the correct values' do + expect(subject.info[:name]).to eql('John Doe') + expect(subject.info[:selfie]).to eql('selfie.png') + expect(subject.info[:full_name]).to eql('John Doe') + expect(subject.info[:given_names]).to eql('John') + expect(subject.info[:family_name]).to eql('Doe') + expect(subject.info[:phone_number]).to eql('07474747474') + expect(subject.info[:email_address]).to eql('email@domain.com') + expect(subject.info[:date_of_birth]).to eql('2000.12.12') + expect(subject.info[:postal_address]).to eql('WC2N 4JH') + expect(subject.info[:gender]).to eql('male') + expect(subject.info[:nationality]).to eql('British') + expect(subject.info[:base64_selfie_uri]).to eql('data:image/jpeg;base64,/9j/2wCEAAMCAg') + expect(subject.info[:age_verified]).to eql(true) + end end end @@ -60,64 +82,42 @@ context 'when using a mock request' do it 'has the correct selfie' do selfie = File.read('spec/fixtures/selfie.txt', encoding: 'utf-8') - expect('data:image/jpeg;base64,'.concat(Base64.strict_encode64(subject.extra[:selfie]))).to eql(selfie) + expect('data:image/jpeg;base64,'.concat(Base64.strict_encode64(subject.extra[:raw_info]['selfie']))).to eql(selfie) end it 'has the correct phone number' do - expect(subject.extra[:phone_number]).to eql('+447474747474') + expect(subject.extra[:raw_info]['phone_number']).to eql('+447474747474') end end context 'when using a mock object' do before do - allow(subject).to receive(:yoti_user_profile).and_return(raw_info_hash) - end - - it 'has the correct selfie' do - expect(subject.extra[:selfie]).to eql('selfie.png') - end - - it 'has the correct given names' do - expect(subject.extra[:given_names]).to eql('Given Names') - end - - it 'has the correct family name' do - expect(subject.extra[:family_name]).to eql('Family Name') + allow(subject).to receive(:yoti_user_profile).and_return(yoti_user_profile_mock) end - it 'has the correct mobile number' do - expect(subject.extra[:phone_number]).to eql('07474747474') - end - - it 'has the correct email address' do - expect(subject.extra[:email_address]).to eql('email@domain.com') - end - - it 'has the correct date of birth' do - expect(subject.extra[:date_of_birth]).to eql('2000.12.12') - end - - it 'has the correct postal address' do - expect(subject.extra[:postal_address]).to eql('WC2N 4JH') - end - - it 'has the correct gender' do - expect(subject.extra[:gender]).to eql('male') - end - - it 'has the correct nationality' do - expect(subject.extra[:nationality]).to eql('British') + it 'returns the correct values' do + expect(subject.extra[:raw_info]['selfie']).to eql('selfie.png') + expect(subject.extra[:raw_info]['full_name']).to eql('John Doe') + expect(subject.extra[:raw_info]['given_names']).to eql('John') + expect(subject.extra[:raw_info]['family_name']).to eql('Doe') + expect(subject.extra[:raw_info]['phone_number']).to eql('07474747474') + expect(subject.extra[:raw_info]['email_address']).to eql('email@domain.com') + expect(subject.extra[:raw_info]['date_of_birth']).to eql('2000.12.12') + expect(subject.extra[:raw_info]['postal_address']).to eql('WC2N 4JH') + expect(subject.extra[:raw_info]['gender']).to eql('male') + expect(subject.extra[:raw_info]['nationality']).to eql('British') end end end private - def raw_info_hash + def yoti_user_profile_mock { 'selfie' => 'selfie.png', - 'given_names' => 'Given Names', - 'family_name' => 'Family Name', + 'full_name' => 'John Doe', + 'given_names' => 'John', + 'family_name' => 'Doe', 'phone_number' => '07474747474', 'email_address' => 'email@domain.com', 'date_of_birth' => '2000.12.12', @@ -126,4 +126,12 @@ def raw_info_hash 'nationality' => 'British' } end + + def base64_selfie_uri_mock + 'data:image/jpeg;base64,/9j/2wCEAAMCAg' + end + + def age_verified_mock + true + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 09b7e80..eb56a24 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,6 @@ require 'simplecov' SimpleCov.start -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) +$LOAD_PATH.unshift File.expand_path('../lib', __dir__) require 'omniauth/yoti' require 'webmock/rspec'