Skip to content
This repository was archived by the owner on Aug 10, 2021. It is now read-only.

Commit f11a39e

Browse files
author
Vasile Zaremba
committed
Add specs and general tweaks
1 parent d61da60 commit f11a39e

File tree

14 files changed

+207
-33
lines changed

14 files changed

+207
-33
lines changed

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
--format documentation
22
--color
3+
--order random

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
source 'https://rubygems.org'
22

3+
gem 'guard'
4+
gem 'guard-rspec'
5+
gem 'pry'
6+
gem 'pry-byebug'
7+
gem 'rubocop'
8+
39
gemspec

Guardfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
guard :rspec, cmd: 'bundle exec rspec -c -f doc' do
2+
# watch /lib/ files
3+
watch(%r{^lib/(.+).rb$}) do |m|
4+
"spec/#{m[1]}_spec.rb"
5+
end
6+
7+
# watch /spec/ files
8+
watch(%r{^spec/(.+).rb$}) do |m|
9+
"spec/#{m[1]}.rb"
10+
end
11+
end

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ This gem contains the Yoti strategy for OmniAuth.
66

77
You should have already installed OmniAuth into your app. If not, read the [OmniAuth README](https://github.com/omniauth/omniauth) to get started.
88

9-
Now sign in into the [Yoti dashboard](https://www.yoti.com/dashboard/login) and create an application. Take note of your Application ID and Yoti client SDK ID because that is what your web application will use to authenticate against the Yoti API. Make sure to set a callback URL and download the pem key.
10-
11-
An Ruby on Rails example app that implements the Yoti OmniAuth strategy can be found in [Yoti Web Labs](https://github.com/lampkicking/yoti-web-labs/tree/master/voting-app)
9+
Now sign in into the [Yoti dashboard](https://www.yoti.com/dashboard/login) and create an application. Take note of your Application ID and Yoti client SDK ID because that is what your web application will use to authenticate against the Yoti API. Make sure to set a callback URL to `YOUR_SITE/auth/yoti/callback`, and download the pem key.
1210

1311
## Using This Strategy
1412

@@ -20,11 +18,15 @@ gem 'omniauth-yoti'
2018

2119
And then execute:
2220

23-
$ bundle
21+
```shell
22+
$ bundle
23+
```
2424

2525
Or install it yourself as:
2626

27-
$ gem install omniauth-yoti
27+
```shell
28+
$ gem install omniauth-yoti
29+
```
2830

2931
## Configuration
3032

@@ -44,17 +46,17 @@ end
4446

4547
`YOTI_APPLICATION_ID` - found on the *Integrations* settings page, under the Login button section.
4648

47-
`YOTI_CLIENT_SDK_ID` - found on the *Integrations* settings page
49+
`YOTI_CLIENT_SDK_ID` - found on the *Integrations* settings page.
4850

49-
`YOTI_KEY_FILE_PATH` - the full path to your security key downloaded from the *Keys* settings page (e.g. /Users/developer/access-security.pem)
51+
`YOTI_KEY_FILE_PATH` - the full path to your security key downloaded from the *Keys* settings page (e.g. /Users/developer/access-security.pem).
5052

5153
If you don't have access to the file system to store the pem file, you can replace `key_file_path` with `key`, that stores a string with the content of the secret key (`key: "-----BEGIN RSA PRIVATE KEY-----\nMIIEp..."`).
5254

5355
The configuration values are documented in the [Yoti gem repository](https://github.com/lampkicking/yoti-sdk-server-ruby#configuration).
5456

5557
## Authentication
5658

57-
A call to `/auth/yoti/callback` will open the Yoti authentication page, and after a sucessful authentication, you will be redirected to the callback URL from your Yoti dasboard. The auth hash will be available in `request.env['omniauth.auth']`:
59+
A call to `/auth/yoti/callback` will open the Yoti authentication page, and after a successful authentication, you will be redirected to the callback URL from your Yoti dashboard. The auth hash will be available in `request.env['omniauth.auth']`:
5860

5961
```ruby
6062
{

lib/omniauth/strategies/yoti.rb

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,55 @@ module Strategies
66
class Yoti
77
include OmniAuth::Strategy
88

9-
option :config, [:application_id, :client_sdk_id, :key_file_path, :key]
9+
option :client_options
1010

1111
def request_phase
12-
redirect "https://www.yoti.com/connect/#{options.config.first.application_id}"
12+
redirect "https://www.yoti.com/connect/#{options.client_options[:application_id]}"
1313
end
1414

15-
uid { @yoti_activity_details.user_id }
16-
info { { name: @yoti_activity_details.user_id } }
15+
uid { yoti_user_id }
16+
info { { name: yoti_user_id } }
1717

1818
def extra
19-
@raw_info ||= begin
20-
user_profile = @yoti_activity_details.user_profile
21-
{
22-
photo: user_profile['selfie'],
23-
given_names: user_profile['given_names'],
24-
family_name: user_profile['family_name'],
25-
mobile_number: user_profile['phone_number'],
26-
date_of_birth: user_profile['date_of_birth'],
27-
address: user_profile['post_code'],
28-
gender: user_profile['gender'],
29-
nationality: user_profile['nationality']
30-
}
19+
@raw_info ||= {
20+
photo: yoti_user_profile['selfie'],
21+
given_names: yoti_user_profile['given_names'],
22+
family_name: yoti_user_profile['family_name'],
23+
mobile_number: yoti_user_profile['phone_number'],
24+
date_of_birth: yoti_user_profile['date_of_birth'],
25+
address: yoti_user_profile['post_code'],
26+
gender: yoti_user_profile['gender'],
27+
nationality: yoti_user_profile['nationality']
28+
}
29+
end
30+
31+
private
32+
33+
def yoti_activity_details
34+
@yoti_activity_details ||= begin
35+
configure_yoti_client!
36+
::Yoti::Client.get_activity_details(token)
3137
end
3238
end
3339

34-
def callback_phase
40+
def yoti_user_profile
41+
yoti_activity_details.user_profile
42+
end
43+
44+
def yoti_user_id
45+
yoti_activity_details.user_id
46+
end
47+
48+
def configure_yoti_client!
3549
::Yoti.configure do |config|
36-
config.client_sdk_id = options.config.first['client_sdk_id']
37-
config.key_file_path = options.config.first['key_file_path']
38-
config.key = options.config.first['key']
50+
config.client_sdk_id = options.client_options[:client_sdk_id]
51+
config.key_file_path = options.client_options[:key_file_path]
52+
config.key = options.client_options[:key]
3953
end
54+
end
4055

41-
token = Rack::Utils.parse_nested_query(request.query_string)['token']
42-
@yoti_activity_details = ::Yoti::Client.get_activity_details(token)
43-
44-
super
56+
def token
57+
Rack::Utils.parse_nested_query(request.query_string)['token']
4558
end
4659
end
4760
end

lib/omniauth/yoti/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Omniauth
22
module Yoti
3-
VERSION = '0.1.0'
3+
VERSION = '0.1.0'.freeze
44
end
55
end

omniauth-yoti.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
2424
spec.add_development_dependency 'bundler', '~> 1.13'
2525
spec.add_development_dependency 'rake', '~> 10.0'
2626
spec.add_development_dependency 'rspec', '~> 3.0'
27+
spec.add_development_dependency 'simplecov'
28+
spec.add_development_dependency 'webmock'
2729
end

rubocop.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
AllCops:
2+
DisplayCopNames: true
3+
DisplayStyleGuide: true
4+
TargetRubyVersion: 2.3
5+
6+
Metrics/AbcSize:
7+
Max: 20
8+
9+
Metrics/LineLength:
10+
Enabled: false
11+
12+
Metrics/MethodLength:
13+
CountComments: false
14+
Max: 15
15+
16+
Style/Documentation:
17+
Enabled: false
18+
19+
Style/FrozenStringLiteralComment:
20+
Enabled: false
21+
22+
Style/NumericLiterals:
23+
Enabled: false
24+
25+
Style/FileName:
26+
Enabled: false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c31Db4y6ClxSWy26xDpa9LEX3ZTUuR-rKaAhjQWnmKilR20IshkysR5Y3Hh3R6hanOyxcu7fl5vbjikkGZZb3_iH6NjxmBXuGY_Fr23AhrHvGL9WMg4EtemVvr6VI2f_5H_PDhDpYUvv-YpEM0f_SReoVxGIc8VGfj1gukuhPyNJ9hs55-SDdUjN77JiA6FPcYZxEIaqQE_yT_c3Y4V72Jnq3RHbG0vL6SefSfY_fFsnx_HeddsJc10qJYCwAkdGzVzbJH2DQ2Swp821Gwyj9eNK54S6HvpIg7LclID7BtymG6z7cTNp3fXX7mgKYoQlh_DHmPmaiqyj398w424RBg==

spec/fixtures/payload_v1.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)