omniauth-medpass 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-medpass.gemspec
4
+ gemspec
5
+
6
+ group :example do
7
+ gem 'sinatra'
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Karol Sarnacki
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,138 @@
1
+ # OmniAuth Medpass  [![Build Status](https://secure.travis-ci.org/connectmedica/omniauth-medpass.png)][travis] [![Dependency Status](https://gemnasium.com/connectmedica/omniauth-medpass.png?travis)][gemnasium]
2
+
3
+ Medpass OAuth2 Strategy for [OmniAuth 1.0](https://github.com/intridea/omniauth) authentication system.
4
+
5
+ [travis]: http://travis-ci.org/connectmedica/omniauth-medpass
6
+ [gemnasium]: https://gemnasium.com/connectmedica/omniauth-medpass
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'omniauth-medpass'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install omniauth-medpass
21
+
22
+ ## Quick start
23
+
24
+ $ MEDPASS_API_KEY="your_medpass_api_key" ruby examples/sinatra.rb
25
+
26
+ ## Configuration
27
+
28
+ ```ruby
29
+ require 'omniauth-medpass'
30
+ require 'openid/store/filesystem'
31
+
32
+ use Rack::Session::Cookie
33
+ use OmniAuth::Strategies::Medpass, ENV['MEDPASS_API_KEY'], :store => OpenID::Store::Filesystem.new('/tmp')
34
+ ```
35
+
36
+ Block style:
37
+
38
+ ```ruby
39
+ require 'omniauth-medpass'
40
+ require 'openid/store/filesystem'
41
+
42
+ use OmniAuth::Builder do
43
+ provider :medpass, 'YOUR_MEDPASS_API_KEY', :store => OpenID::Store::Filesystem.new('/tmp')
44
+ end
45
+ ```
46
+
47
+ *Medpass API Key* is optional - you do not need it to successfully authenticate user - but if you provide it, you will have access to full Auth Hash data.
48
+
49
+ For more information about configuring OpenID strategy, see [original documentation](https://github.com/intridea/omniauth-openid).
50
+
51
+ Note that default OpenID stores (`memory` and `filesystem`) will not work on clustered servers (unless they all share same store path).
52
+
53
+ ## Usage
54
+
55
+ ```html
56
+ <a href="/auth/medpass">Sign in with Medpass</a>
57
+ ```
58
+
59
+ ...and then retrieve authenticated user data in callback (here using Sinatra):
60
+
61
+ ```ruby
62
+ post '/auth/unipass/callback' do
63
+ User.create(:id => request.env['omniauth.auth'].id)
64
+ end
65
+ ```
66
+
67
+ ## Auth Hash
68
+
69
+ Exemplary Auth Hash obtained after successful authentication:
70
+
71
+ ```ruby
72
+ {
73
+ 'provider' => 'medpass',
74
+ 'id' => 'eilda.bleet',
75
+ 'info' => {
76
+ 'name' => 'Eilda Bleet',
77
+ 'email' => 'eilda@bleet.com',
78
+ 'nickname' => 'anonimowy użytkownik', # user can hide his display_name
79
+ 'first_name' => 'Eilda',
80
+ 'last_name' => 'Bleet',
81
+ 'location' => 'Poznań',
82
+ 'description' => 'Absolwentka wyższej szkoły organizacji turystyki i hotelarstwa.',
83
+ 'image' => 'http://medpass.pl/profile/get_avatar?login=eilda.bleet&size=small',
84
+ 'phone' => nil,
85
+ 'urls' => {
86
+ 'medpass' => 'http://eilda.bleet.medpass.pl'
87
+ }
88
+ },
89
+ 'extra' => {
90
+ 'raw_info' => {
91
+ 'medpass_id' => 123,
92
+ 'login' => 'eilda.bleet',
93
+ 'firstname' => 'Eilda',
94
+ 'lastname' => 'Bleet',
95
+ 'title' => 'Dr',
96
+ 'display_name' => 'anonimowy użytkownik',
97
+ 'email' => 'eilda@bleet.com'
98
+ 'group' => 2,
99
+ 'group_key' => 'DOC',
100
+ 'city' => 'Poznań',
101
+ 'address' => 'Lipna 27',
102
+ 'postcode' => '01-234',
103
+ 'mobile_phone' => '521324354',
104
+ 'phone' => '229876543',
105
+ 'skype' => 'eilda1717',
106
+ 'gadu' => nil,
107
+ 'pwz' => '696969',
108
+ 'speciality' => nil,
109
+ 'about' => 'I love pancakes!',
110
+ 'gender' => 1,
111
+ 'company_name' => 'Activeweb',
112
+ 'company_address' => 'Wiatru w polu 3',
113
+ 'company_city' => 'Gdynia',
114
+ 'company_postcode' => nil,
115
+ 'company_province' => 'śląskodąbrowskie',
116
+ 'company_phone' => nil,
117
+ 'is_superviewer' => false,
118
+ 'province' => {
119
+ 'province' => {
120
+ 'name' => 'mazowieckie',
121
+ 'code' => '14',
122
+ 'id' => 7
123
+ }
124
+ }
125
+ }
126
+ }
127
+ }
128
+ ```
129
+
130
+ Note that this information is available only if you provide valid Medpass API Key.
131
+
132
+ ## Contributing
133
+
134
+ 1. Fork it
135
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
136
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
137
+ 4. Push to the branch (`git push origin my-new-feature`)
138
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+ task :test => :spec
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.setup :default, :development, :example
5
+
6
+ require 'sinatra'
7
+ require 'omniauth-medpass'
8
+
9
+ use Rack::Session::Cookie
10
+ use OmniAuth::Strategies::Medpass, ENV['MEDPASS_API_KEY']
11
+
12
+ get '/' do
13
+ <<-HTML
14
+ <ul>
15
+ <li><a href='/auth/medpass'>Sign in with Medpass</a></li>
16
+ </ul>
17
+ HTML
18
+ end
19
+
20
+ [:get, :post].each do |method|
21
+ send method, '/auth/:provider/callback' do
22
+ '<dl>' + request.env['omniauth.auth'].info.map{ |k, v| "<dt>#{k}</dt><dd>#{v.inspect}</dd>" }.join + '</dl>'
23
+ end
24
+ end
@@ -0,0 +1,2 @@
1
+ require 'omniauth-medpass/version'
2
+ require 'omniauth/strategies/medpass'
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Medpass
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,106 @@
1
+ require 'omniauth/strategies/open_id'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Medpass < OmniAuth::Strategies::OpenID
7
+ URI_SCHEME_REGEXP = /[#{URI::REGEXP::PATTERN::ALPHA}][-+.#{URI::REGEXP::PATTERN::ALPHA}\d]*/
8
+
9
+ args :api_key
10
+
11
+ option :api_key, nil
12
+ option :name, :medpass
13
+ option :site, 'http://medpass.pl'
14
+ option :openid_url_scheme, 'http://%{login}.medpass.pl'
15
+ option :identifier_param, 'login'
16
+
17
+ uid { openid_response.display_identifier }
18
+
19
+ info do
20
+ {
21
+ 'email' => raw_info['email'],
22
+ 'nickname' => raw_info['display_name'], # Also available: openid_response.display_identifier
23
+ 'first_name' => raw_info['firstname'],
24
+ 'last_name' => raw_info['lastname'],
25
+ 'location' => raw_info['city'], # Also available: address, postcode, province
26
+ 'description' => raw_info['about'],
27
+ 'image' => user_avatar_uri.to_s,
28
+ 'phone' => raw_info['phone'], # Also available: mobile_phone
29
+ 'urls' => {
30
+ options.name.to_s => openid_url
31
+ }
32
+ }
33
+ end
34
+
35
+ extra do
36
+ { 'raw_info' => raw_info }
37
+ end
38
+
39
+ def get_identifier
40
+ f = OmniAuth::Form.new(:title => 'Medpass Authentication')
41
+ f.label_field('Medpass Identifier', options.identifier_param)
42
+ f.input_field('url', options.identifier_param)
43
+ f.to_response
44
+ end
45
+
46
+ def identifier
47
+ i = request.params[options.identifier_param.to_s]
48
+ i = i !~ /\S/ ? nil : openid_url_from_login(i)
49
+ i
50
+ end
51
+
52
+ private
53
+
54
+ def raw_info
55
+ @raw_info ||= options.api_key ? MultiJson.decode(Net::HTTP.get(user_profile_uri)) : {}
56
+ end
57
+
58
+ def user_profile_uri
59
+ @user_profile_uri ||= URI.parse("#{options.site}/resource_api/users/#{encode_login(login)}?api_key=#{options.api_key}&full_profile=1")
60
+ end
61
+
62
+ def user_avatar_uri
63
+ @user_avatar_uri ||= URI.parse("#{options.site}/profile/get_avatar?login=#{login}&size=small") # "Small" = 50x50
64
+ end
65
+
66
+ def login
67
+ @login ||= login_from_openid_url(openid_response.display_identifier)
68
+ end
69
+
70
+ def openid_url
71
+ @openid_url ||= openid_url_from_login(openid_response.display_identifier)
72
+ end
73
+
74
+ def login_from_openid_url(openid_url)
75
+ return nil if openid_url !~ /\S/
76
+
77
+ # Remove parts guessed from options[:openid_url_scheme]
78
+ parts = options.openid_url_scheme.rpartition('%{login}')
79
+ openid_url.gsub!(/^#{parts.first}/, '')
80
+ openid_url.gsub!(/#{parts.last}$/, '')
81
+
82
+ # Remove host and port guessed from options[:site]
83
+ uri = URI.parse(options.site)
84
+ openid_url.gsub!(/\.#{uri.host}(?::\d*)?\/*$/, '')
85
+
86
+ # Remove some common parts - scheme and trailing slashes
87
+ openid_url.gsub!(/^#{URI_SCHEME_REGEXP}:\/\//, '')
88
+ openid_url.gsub!(/\/+$/, '')
89
+
90
+ openid_url
91
+ end
92
+
93
+ def openid_url_from_login(login)
94
+ return nil if login !~ /\S/
95
+
96
+ options.openid_url_scheme % {:login => login_from_openid_url(login)}
97
+ end
98
+
99
+ def encode_login(login)
100
+ login.to_s.gsub('.', '-dot-')
101
+ end
102
+
103
+ end
104
+ end
105
+ end
106
+
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-medpass/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ['Karol Sarnacki']
6
+ gem.email = ['sodercober@gmail.com']
7
+ gem.description = %q{Medpass OpenID Strategy for OmniAuth 1.0}
8
+ gem.summary = %q{Medpass OpenID Strategy for OmniAuth 1.0}
9
+ gem.homepage = 'https://github.com/connectmedica/omniauth-medpass'
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = 'omniauth-medpass'
15
+ gem.require_paths = ['lib']
16
+ gem.version = Omniauth::Medpass::VERSION
17
+
18
+ gem.add_runtime_dependency 'multi_json'
19
+ gem.add_runtime_dependency 'omniauth-openid', '~> 1.0.0'
20
+
21
+ gem.add_development_dependency 'rack-test'
22
+ gem.add_development_dependency 'rake'
23
+ gem.add_development_dependency 'rspec', '~> 2.8.0'
24
+ gem.add_development_dependency 'simplecov'
25
+ gem.add_development_dependency 'webmock'
26
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Medpass, :type => :strategy do
4
+
5
+ def app
6
+ strat = OmniAuth::Strategies::Medpass
7
+ Rack::Builder.new {
8
+ use Rack::Session::Cookie
9
+ use strat
10
+ run lambda{ |env| [404, {'Content-Type' => 'text/plain'}, [nil || env.key?('omniauth.auth').to_s]] }
11
+ }.to_app
12
+ end
13
+
14
+ def expired_query_string
15
+ 'openid=consumer&janrain_nonce=2011-07-21T20%3A14%3A56ZJ8LP3T&openid.assoc_handle=%7BHMAC-SHA1%7D%7B4e284c39%7D%7B9nvQeg%3D%3D%7D&openid.claimed_id=http%3A%2F%2Flocalhost%3A1123%2Fjohn.doe%3Fopenid.success%3Dtrue&openid.identity=http%3A%2F%2Flocalhost%3A1123%2Fjohn.doe%3Fopenid.success%3Dtrue&openid.mode=id_res&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.op_endpoint=http%3A%2F%2Flocalhost%3A1123%2Fserver%2F%3Fopenid.success%3Dtrue&openid.response_nonce=2011-07-21T20%3A14%3A56Zf9gC8S&openid.return_to=http%3A%2F%2Flocalhost%3A8888%2FDevelopment%2FWordpress%2Fwp_openid%2F%3Fopenid%3Dconsumer%26janrain_nonce%3D2011-07-21T20%253A14%253A56ZJ8LP3T&openid.sig=GufV13SUJt8VgmSZ92jGZCFBEvQ%3D&openid.signed=assoc_handle%2Cclaimed_id%2Cidentity%2Cmode%2Cns%2Cop_endpoint%2Cresponse_nonce%2Creturn_to%2Csigned'
16
+ end
17
+
18
+ describe '/auth/medpass without an identifier URL' do
19
+ before do
20
+ get '/auth/medpass'
21
+ end
22
+
23
+ it 'responds with OK' do
24
+ last_response.should be_ok
25
+ end
26
+
27
+ it 'responds with HTML' do
28
+ last_response.content_type.should == 'text/html'
29
+ end
30
+
31
+ it 'renders an identifier URL input' do
32
+ last_response.body.should =~ %r{<input[^>]*login}
33
+ end
34
+ end
35
+
36
+ describe 'followed by /auth/open_id/callback' do
37
+ context 'successful' do
38
+ #before do
39
+ # @identifier_url = 'http://me.example.org'
40
+ # # TODO: change this mock to actually return some sort of OpenID response
41
+ # stub_request(:get, @identifier_url)
42
+ # get '/auth/open_id/callback'
43
+ #end
44
+
45
+ it 'sets provider to medpass'
46
+ it 'creates auth_hash based on sreg'
47
+ it 'creates auth_hash based on Medpass Resource API'
48
+
49
+ #it 'calls through to the master app' do
50
+ # last_response.body.should == 'true'
51
+ #end
52
+ end
53
+
54
+ context 'unsuccessful' do
55
+ describe 'returning with expired credentials' do
56
+ before do
57
+ # get '/auth/open_id/callback?' + expired_query_string
58
+ end
59
+
60
+ it 'it redirects to invalid credentials' do
61
+ pending
62
+ last_response.should be_redirect
63
+ last_response.headers['Location'].should =~ %r{invalid_credentials}
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,14 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+
6
+ require 'rspec'
7
+ require 'rack/test'
8
+ require 'webmock/rspec'
9
+ require 'omniauth-medpass'
10
+
11
+ RSpec.configure do |config|
12
+ config.include WebMock::API
13
+ config.include Rack::Test::Methods
14
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-medpass
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Karol Sarnacki
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: multi_json
16
+ requirement: &70361615718160 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70361615718160
25
+ - !ruby/object:Gem::Dependency
26
+ name: omniauth-openid
27
+ requirement: &70361615717660 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70361615717660
36
+ - !ruby/object:Gem::Dependency
37
+ name: rack-test
38
+ requirement: &70361615717240 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70361615717240
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &70361615716780 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70361615716780
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &70361615716280 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 2.8.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70361615716280
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: &70361615715860 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70361615715860
80
+ - !ruby/object:Gem::Dependency
81
+ name: webmock
82
+ requirement: &70361615715400 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70361615715400
91
+ description: Medpass OpenID Strategy for OmniAuth 1.0
92
+ email:
93
+ - sodercober@gmail.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - .gitignore
99
+ - .travis.yml
100
+ - Gemfile
101
+ - LICENSE
102
+ - README.md
103
+ - Rakefile
104
+ - examples/sinatra.rb
105
+ - lib/omniauth-medpass.rb
106
+ - lib/omniauth-medpass/version.rb
107
+ - lib/omniauth/strategies/medpass.rb
108
+ - omniauth-medpass.gemspec
109
+ - spec/omniauth/strategies/medpass_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: https://github.com/connectmedica/omniauth-medpass
112
+ licenses: []
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ segments:
124
+ - 0
125
+ hash: 2705916791591618707
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ segments:
133
+ - 0
134
+ hash: 2705916791591618707
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 1.8.11
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Medpass OpenID Strategy for OmniAuth 1.0
141
+ test_files:
142
+ - spec/omniauth/strategies/medpass_spec.rb
143
+ - spec/spec_helper.rb