ipizza-omniauth-provider 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +29 -0
- data/Rakefile +20 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/ipizza_omniauth_provider.rb +8 -0
- data/lib/omniauth/strategies/ipizza.rb +92 -0
- metadata +72 -0
data/README.markdown
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
iPizza auth strategy for OmniAuth
|
2
|
+
=================================
|
3
|
+
|
4
|
+
iPizza authentication strategy provider for [Omniauth](https://github.com/intridea/omniauth). Uses [ipizza gem](https://github.com/priithaamer/ipizza) as dependency.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
Add gem dependency in your `Gemfile` and install the gem:
|
10
|
+
|
11
|
+
gem 'ipizza-omniauth-provider'
|
12
|
+
|
13
|
+
Usage
|
14
|
+
-----
|
15
|
+
|
16
|
+
Make sure you have iPizza configured properly in `config/ipizza.yml` file. See the instructions from [ipizza gem page](https://github.com/priithaamer/ipizza).
|
17
|
+
|
18
|
+
For Rails 3, in devise configuration file, e.g `config/initializers/load_devise.rb`, declare ipizza authentication strategy:
|
19
|
+
|
20
|
+
Devise.setup do |config|
|
21
|
+
|
22
|
+
# <your existing devise config>
|
23
|
+
|
24
|
+
config.omniauth :ipizza,
|
25
|
+
'Authenticate with iPizza',
|
26
|
+
:logger => Logger.new('log/ipizza_auth.log'),
|
27
|
+
:config => Rails.root.join('config/ipizza.yml')
|
28
|
+
end
|
29
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gemspec|
|
7
|
+
gemspec.name = 'ipizza-omniauth-provider'
|
8
|
+
|
9
|
+
gemspec.summary = 'iPizza authentication strategy provider for Omniauth'
|
10
|
+
gemspec.description = <<-DESC
|
11
|
+
Integrates iPizza authentication to your rails app almost effortlessly.
|
12
|
+
DESC
|
13
|
+
|
14
|
+
gemspec.email = 'priit@fraktal.ee'
|
15
|
+
gemspec.homepage = 'http://github.com/priithaamer/ipizza-omniauth-provider'
|
16
|
+
gemspec.authors = ['Priit Haamer']
|
17
|
+
end
|
18
|
+
rescue LoadError
|
19
|
+
puts 'Jeweler not available. Install it with: gem install jeweler'
|
20
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'ipizza_omniauth_provider'
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'ipizza'
|
2
|
+
require 'omniauth/oauth'
|
3
|
+
require 'rack/utils'
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
module Strategies
|
7
|
+
class Ipizza
|
8
|
+
include OmniAuth::Strategy
|
9
|
+
|
10
|
+
attr_accessor :logger
|
11
|
+
|
12
|
+
def initialize(app, title, options = {})
|
13
|
+
super(app, :ipizza)
|
14
|
+
|
15
|
+
@title = title
|
16
|
+
self.logger = options.delete(:logger)
|
17
|
+
|
18
|
+
::Ipizza::Config.load_from_file(options.delete(:config))
|
19
|
+
end
|
20
|
+
|
21
|
+
def request_phase
|
22
|
+
if env['REQUEST_METHOD'] == 'GET'
|
23
|
+
get_credentials
|
24
|
+
else
|
25
|
+
provider = ipizza_provider_for(request.params['bank'])
|
26
|
+
|
27
|
+
req = provider.authentication_request
|
28
|
+
url = [req.service_url, Rack::Utils.build_query(req.request_params)] * '?'
|
29
|
+
|
30
|
+
redirect url
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_credentials
|
35
|
+
OmniAuth::Form.build(@title) do
|
36
|
+
text_field 'Bank', 'bank'
|
37
|
+
end.to_response
|
38
|
+
end
|
39
|
+
|
40
|
+
def callback_phase
|
41
|
+
debug "Callback in iPizza authentication. Parameters: #{request.params.inspect}"
|
42
|
+
|
43
|
+
@env['REQUEST_METHOD'] = 'GET'
|
44
|
+
|
45
|
+
provider = ipizza_provider_for(request.params['VK_SND_ID'])
|
46
|
+
resp = provider.authentication_response(request.params)
|
47
|
+
|
48
|
+
if resp.success? and resp.valid?
|
49
|
+
@user_data = {'personal_code' => resp.info_social_security_id, 'name' => resp.info_name}
|
50
|
+
@env['omniauth.auth'] = auth_hash
|
51
|
+
|
52
|
+
debug "iPizza request was authenticated successfully. User data: #{auth_hash.inspect}"
|
53
|
+
|
54
|
+
call_app!
|
55
|
+
else
|
56
|
+
debug 'Could not authenticate iPizza request'
|
57
|
+
fail!(:invalid_credentials, {'error' => 'Invalid bank response'})
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def user_info
|
62
|
+
@user_data
|
63
|
+
end
|
64
|
+
|
65
|
+
def auth_hash
|
66
|
+
OmniAuth::Utils.deep_merge(super, {'uid' => @user_data['personal_code'], 'user_info' => user_info})
|
67
|
+
end
|
68
|
+
|
69
|
+
def debug(message)
|
70
|
+
logger.debug("#{Time.now} #{message}") if logger
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def ipizza_provider_for(bank)
|
76
|
+
case bank.downcase
|
77
|
+
when 'swedbank'
|
78
|
+
::Ipizza::Provider::Swedbank.new
|
79
|
+
when 'eyp'
|
80
|
+
::Ipizza::Provider::Seb.new
|
81
|
+
when 'seb'
|
82
|
+
::Ipizza::Provider::Seb.new
|
83
|
+
when 'sampo'
|
84
|
+
::Ipizza::Provider::Sampo.new
|
85
|
+
when 'nordea'
|
86
|
+
::Ipizza::Provider::Nordea.new
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ipizza-omniauth-provider
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Priit Haamer
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-04 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: " Integrates iPizza authentication to your rails app almost effortlessly.\n"
|
23
|
+
email: priit@fraktal.ee
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.markdown
|
30
|
+
files:
|
31
|
+
- README.markdown
|
32
|
+
- Rakefile
|
33
|
+
- VERSION
|
34
|
+
- init.rb
|
35
|
+
- lib/ipizza_omniauth_provider.rb
|
36
|
+
- lib/omniauth/strategies/ipizza.rb
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://github.com/priithaamer/ipizza-omniauth-provider
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options:
|
43
|
+
- --charset=UTF-8
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
hash: 3
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
version: "0"
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.7
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: iPizza authentication strategy provider for Omniauth
|
71
|
+
test_files: []
|
72
|
+
|