omniauth-samedi 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 72b022445a5b50c7242b3643f9116c0a944aa41bfa810a8fadacdf4884021837
4
+ data.tar.gz: dd564547dfc87150b07f2830d27a8933295255ce2a816ab275b933a3625a232a
5
+ SHA512:
6
+ metadata.gz: b4927fbdd2cad2ef84d6af90c2e0cfb08673932ffdafca02c75cf769514c8334a304c46f6965756e9dd18d3a968429d5d0aacafb3c5b136ce7f3664091e415b2
7
+ data.tar.gz: 579810450b60ea98ec6a97eff0ae3d151be3dea5da4241eab0e9053c96fede0ee049b36190c61787d4b6488041953192a3b329fe70c4f8432fb6945532495c0f
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 samedi GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,59 @@
1
+ # OmniAuth Samedi
2
+
3
+ [![Build Status](https://travis-ci.com/samedi/omniauth-samedi.svg?branch=master)](https://travis-ci.com/samedi/omniauth-samedi)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/3c597b941cd1fdbce47e/maintainability)](https://codeclimate.com/github/samedi/omniauth-samedi/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/3c597b941cd1fdbce47e/test_coverage)](https://codeclimate.com/github/samedi/omniauth-samedi/test_coverage)
6
+
7
+ Samedi® authentication strategy for OmniAuth.
8
+
9
+ The strategy implements the OAuth 2.0 flow for authentication with samedi®, as described in [samedi® Booking API docs](https://wiki.samedi.de/display/doc/Booking+API#BookingAPI-AuthenticationandAuthorization) and also fetches basic [user information](https://wiki.samedi.de/display/doc/Booking+API#BookingAPI-UserInformation).
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'omniauth-samedi'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install omniauth-samedi
26
+
27
+ ## Usage
28
+
29
+ Obtain your Client Key and Client Secret by [signing up for samedi® API credentials](https://patient.samedi.de/api/signup).
30
+
31
+ You can then add the `samedi` provider in the way that is most appropriate for your app. E.g. if you're using Rails with OmniAuth directly, you can add the following to your `conifg/initializers/omniauth.rb`:
32
+
33
+ ```ruby
34
+ Rails.application.config.middleware.use OmniAuth::Builder do
35
+ provider :samedi, ENV.fetch('CLIENT_ID'), ENV.fetch('CLIENT_SECRET')
36
+ end
37
+ ```
38
+
39
+ After the authentication is performed, the user data is retrieved automatically.
40
+
41
+ For an example of using the strategy within a Rails application, consult the [rails-booking-api](https://github.com/samedi/rails-booking-api) repo.
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/samedi/omniauth-samedi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
56
+
57
+ ## Code of Conduct
58
+
59
+ Everyone interacting in the OmniAuth Samedi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/omniauth-samedi/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-samedi/version'
4
+ require 'omniauth/strategies/samedi'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Omniauth
4
+ module Samedi
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-oauth2'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ # Provides implementation of an OmniAuth strategy that works with samedi Booking API.
8
+ #
9
+ # For more information, consult the OmniAuth Strategy Contribution Guide:
10
+ # https://github.com/omniauth/omniauth/wiki/Strategy-Contribution-Guide
11
+ #
12
+ # Note: this file is explicitly required by config/initializers/omniauth.rb so changes to it
13
+ # won't be automatically reloaded and you need to restart the Rails app after every change to the strategy.
14
+ # Changing `require` to `require_dependency` won't work, because Rails doesn't clear dependencies
15
+ # required by initializers.
16
+ class Samedi < OmniAuth::Strategies::OAuth2
17
+ BOOKING_AUTH_URL = 'https://patient.samedi.de/api/auth/v2'
18
+ BOOKING_API_URL = 'https://patient.samedi.de/api/booking/v3'
19
+
20
+ option :name, 'samedi'
21
+ option(
22
+ :client_options,
23
+ site: BOOKING_AUTH_URL,
24
+ authorize_url: "#{BOOKING_AUTH_URL}/authorize",
25
+ token_url: "#{BOOKING_AUTH_URL}/token"
26
+ )
27
+
28
+ uid do
29
+ user_info.dig('user', 'id')
30
+ end
31
+
32
+ info do
33
+ user_data = user_info['user']
34
+
35
+ if user_data
36
+ {
37
+ name: user_data['full_name'],
38
+ email: user_data['email'],
39
+ first_name: user_data['first_name'],
40
+ last_name: user_data['last_name']
41
+ }
42
+ else
43
+ {}
44
+ end
45
+ end
46
+
47
+ extra do
48
+ { raw_info: user_info['user'] }
49
+ end
50
+
51
+ private
52
+
53
+ # samedi Booking API doesn't like a query string inside redirect_uri, so we need to override it explicitly
54
+ def query_string
55
+ ''
56
+ end
57
+
58
+ def user_info
59
+ return @user_info if @user_info
60
+
61
+ user_info_response = fetch_user_info
62
+ return {} unless user_info_response
63
+
64
+ @user_info = MultiJson.load(user_info_response.body)
65
+ end
66
+
67
+ def fetch_user_info
68
+ response = booking_api_client.get('user')
69
+
70
+ return response if response.success?
71
+
72
+ fail!("error_#{response.status}_getting_user_info")
73
+ nil
74
+ rescue Faraday::TimeoutError => e
75
+ fail!(:timeout_getting_user_info, e)
76
+ nil
77
+ end
78
+
79
+ def booking_api_client
80
+ @booking_api_client ||= Faraday.new(BOOKING_API_URL) do |faraday|
81
+ faraday.headers = { 'Authorization': "Bearer #{access_token.token}" }
82
+ faraday.adapter Faraday.default_adapter
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'omniauth-samedi/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'omniauth-samedi'
9
+ spec.version = Omniauth::Samedi::VERSION
10
+ spec.authors = ['Damir Zekić']
11
+ spec.email = ['damir.zekic@toptal.com']
12
+
13
+ spec.summary = 'Samedi Booking API authentication strategy for OmniAuth'
14
+ spec.description = 'Samedi Booking API authentication strategy for OmniAuth implemented upon OmniAuth OAuth2 strategy.'
15
+ spec.homepage = 'https://github.com/samedi/omniauth-samedi'
16
+ spec.license = 'MIT'
17
+
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['homepage_uri'] = 'https://wiki.samedi.de/display/doc/Booking+API'
20
+ spec.metadata['source_code_uri'] = spec.homepage
21
+ spec.metadata['changelog_uri'] = 'https://github.com/samedi/omniauth-samedi/releases'
22
+ else
23
+ raise 'RubyGems 2.0 or newer is required to publish metadata'
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
29
+ `git ls-files -z`.split("\x0").select { |f| f.match(%r{^(lib/|LICENSE|README|omniauth-samedi\.gemspec)}) }
30
+ end
31
+ spec.bindir = 'exe'
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ['lib']
34
+
35
+ spec.add_dependency 'omniauth', '~> 1.0'
36
+ spec.add_dependency 'omniauth-oauth2', '~> 1.0'
37
+
38
+ spec.add_development_dependency 'addressable', '~> 2.5'
39
+ spec.add_development_dependency 'bundler', '~> 1.16'
40
+ spec.add_development_dependency 'codecov'
41
+ spec.add_development_dependency 'faraday'
42
+ spec.add_development_dependency 'pry'
43
+ spec.add_development_dependency 'rack-test', '~> 1.0'
44
+ spec.add_development_dependency 'rake', '~> 10.0'
45
+ spec.add_development_dependency 'rspec', '~> 3.0'
46
+ spec.add_development_dependency 'rubocop'
47
+ spec.add_development_dependency 'simplecov'
48
+ spec.add_development_dependency 'webmock', '~> 3.4'
49
+ end
metadata ADDED
@@ -0,0 +1,236 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-samedi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Damir Zekić
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: addressable
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: codecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rack-test
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '10.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '10.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '3.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '3.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: webmock
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '3.4'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '3.4'
195
+ description: Samedi Booking API authentication strategy for OmniAuth implemented upon
196
+ OmniAuth OAuth2 strategy.
197
+ email:
198
+ - damir.zekic@toptal.com
199
+ executables: []
200
+ extensions: []
201
+ extra_rdoc_files: []
202
+ files:
203
+ - LICENSE.txt
204
+ - README.md
205
+ - lib/omniauth-samedi.rb
206
+ - lib/omniauth-samedi/version.rb
207
+ - lib/omniauth/strategies/samedi.rb
208
+ - omniauth-samedi.gemspec
209
+ homepage: https://github.com/samedi/omniauth-samedi
210
+ licenses:
211
+ - MIT
212
+ metadata:
213
+ homepage_uri: https://wiki.samedi.de/display/doc/Booking+API
214
+ source_code_uri: https://github.com/samedi/omniauth-samedi
215
+ changelog_uri: https://github.com/samedi/omniauth-samedi/releases
216
+ post_install_message:
217
+ rdoc_options: []
218
+ require_paths:
219
+ - lib
220
+ required_ruby_version: !ruby/object:Gem::Requirement
221
+ requirements:
222
+ - - ">="
223
+ - !ruby/object:Gem::Version
224
+ version: '0'
225
+ required_rubygems_version: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ requirements: []
231
+ rubyforge_project:
232
+ rubygems_version: 2.7.6
233
+ signing_key:
234
+ specification_version: 4
235
+ summary: Samedi Booking API authentication strategy for OmniAuth
236
+ test_files: []