omniauth-mobileid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omniauth-mobileid.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require "omniauth-mobileid/version"
2
+ require "omniauth/strategies/mobileid"
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Mobileid
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,133 @@
1
+ require 'digidoc/client'
2
+ require 'ostruct'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Mobileid
7
+ include OmniAuth::Strategy
8
+
9
+ PhaseReadPin = 'read_pin'
10
+ PhaseAuhtenticated = 'authenticated'
11
+
12
+ option :name, 'mobileid'
13
+ option :service_name, 'Testimine'
14
+ option :country_code, 'EE'
15
+ option :language, 'EST'
16
+ option :message_to_display, 'Test'
17
+ option :messaging_mode, 'asynchClientServer'
18
+ option :async_configuration, 0
19
+ option :endpoint_url, 'https://openxades.org:8443/DigiDocService'
20
+ option :logger, nil
21
+
22
+ def request_phase
23
+ perform
24
+ end
25
+
26
+ def perform
27
+ if request_session_code # Session is in :read_pin status
28
+ get_authentication_status
29
+ else
30
+ perform_authentication
31
+ end
32
+ end
33
+
34
+ def request_session_code
35
+ request.params['session_code']
36
+ end
37
+
38
+ def perform_authentication
39
+ debug 'perform_authentication'
40
+ @auth_data = authenticate(request.params['phone'], request.params['personal_code'])
41
+ debug @auth_data.inspect
42
+
43
+ if user_data[:status] == 'OK'
44
+ @env['omniauth.auth'] = auth_hash
45
+ @env['omniauth.phase'] = PhaseReadPin
46
+ @env['REQUEST_METHOD'] = 'GET'
47
+ @env['PATH_INFO'] = "#{OmniAuth.config.path_prefix}/#{name}/callback"
48
+ call_app!
49
+ else
50
+ fail!(:invalid_credentials, @auth_data)
51
+ end
52
+ end
53
+
54
+ def get_authentication_status
55
+ debug 'get_authentication_status'
56
+ @auth_data = authentication_status(request_session_code)
57
+ debug @auth_data.inspect
58
+ if ['USER_AUTHENTICATED', 'OUTSTANDING_TRANSACTION'].include?(user_data[:status])
59
+ @env['omniauth.phase'] = user_data[:status] == 'USER_AUTHENTICATED' ? PhaseAuhtenticated : PhaseReadPin
60
+ @env['REQUEST_METHOD'] = 'GET'
61
+ @env['PATH_INFO'] = "#{OmniAuth.config.path_prefix}/#{name}/callback"
62
+ call_app!
63
+ else
64
+ fail!(:invalid_credentials, @auth_data)
65
+ end
66
+ end
67
+
68
+ def callback_phase
69
+ debug "callback_phase"
70
+ fail!(:invalid_credentials)
71
+ end
72
+
73
+ def user_data
74
+ @auth_data
75
+ end
76
+
77
+ def auth_hash
78
+ OmniAuth::Utils.deep_merge(super, {
79
+ 'uid' => user_data[:user_id_code],
80
+ 'user_info' => user_info,
81
+ 'read_pin' => {
82
+ 'challenge_id' => user_data[:challenge_id],
83
+ 'session_code' => user_data[:sesscode]},
84
+ 'extra' => {'user_hash' => user_data}
85
+ })
86
+ end
87
+
88
+ def user_info
89
+ {
90
+ 'name' => "#{user_data[:user_givenname]} #{user_data[:user_surname]}",
91
+ 'first_name' => user_data[:user_givenname],
92
+ 'last_name' => user_data[:user_surname],
93
+ 'personal_code' => user_data[:user_id_code],
94
+ 'user_cn' => user_data[:user_cn]
95
+ }
96
+ end
97
+
98
+ # Authentication message
99
+ def authenticate(phone, personal_code)
100
+ data = {
101
+ :phone => phone,
102
+ :personal_code => personal_code,
103
+ :language => options[:language],
104
+ :country_code => options[:country_code],
105
+ :message_to_display => options[:message_to_display],
106
+ :messaging_mode => options[:messaging_mode],
107
+ :async_configuration => options[:async_configuration],
108
+ :return_cert_data => false,
109
+ :return_revocation_data => false
110
+ }
111
+
112
+ self.mobileid_client.authenticate(data)
113
+ end
114
+
115
+ # Authentication status message
116
+ def authentication_status(session_code)
117
+ self.mobileid_client.authentication_status(session_code)
118
+ end
119
+
120
+ protected
121
+
122
+ def debug(message)
123
+ options[:logger].debug("#{Time.now} #{message}") if options[:logger]
124
+ end
125
+
126
+ def mobileid_client
127
+ client = ::Digidoc::Client.new(options[:endpoint_url])
128
+ client.respond_with_nested_struct = false
129
+ client
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-mobileid/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-mobileid"
7
+ s.version = Omniauth::Mobileid::VERSION
8
+ s.authors = ["Tarmo Talu"]
9
+ s.email = ["tarmo.talu@gmail.com"]
10
+ s.homepage = "http://github.com/tarmotalu/omniauth-mobileid"
11
+ s.summary = %q{OmniAuth strategy for Estonian Mobile-ID}
12
+ s.description = %q{OmniAuth strategy for Estonian Mobile-ID}
13
+
14
+ s.rubyforge_project = "omniauth-mobileid"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'omniauth-oauth', '~> 1.0'
22
+ s.add_dependency 'digidoc_client', '~> 0.0.1'
23
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-mobileid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tarmo Talu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth-oauth
16
+ requirement: &70292803097340 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70292803097340
25
+ - !ruby/object:Gem::Dependency
26
+ name: digidoc_client
27
+ requirement: &70292803109240 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.0.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70292803109240
36
+ description: OmniAuth strategy for Estonian Mobile-ID
37
+ email:
38
+ - tarmo.talu@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - Rakefile
46
+ - lib/omniauth-mobileid.rb
47
+ - lib/omniauth-mobileid/version.rb
48
+ - lib/omniauth/strategies/mobileid.rb
49
+ - omniauth-mobileid.gemspec
50
+ homepage: http://github.com/tarmotalu/omniauth-mobileid
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project: omniauth-mobileid
70
+ rubygems_version: 1.8.11
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: OmniAuth strategy for Estonian Mobile-ID
74
+ test_files: []