omniauth-drchrono-oauth2 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 11d425d7ab8ab3a9b65a3bcc0b2c630306ed1ad5
4
+ data.tar.gz: 9c22adc8d8d2840b87cd0c26b0ac85e51a28844d
5
+ SHA512:
6
+ metadata.gz: 3f0c86745b5e77457fc55d4d6f537f8185d4e1f4184980c1df173ffe00b659e8f4737f66a5a27999a4aa535d0d5e9ca70698fbe4739baf03eca4093d32255118
7
+ data.tar.gz: b722a39e3161012ec55d5af09a6c8319282cd69d2cf875afa7298bde45e2296f9e060ed08a3af55629036899f8d137cc5559fd978a7a28b0479dc86f427712b4
@@ -0,0 +1,19 @@
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
18
+ .ruby-gemset
19
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ - 2.3
5
+ - 2.4
6
+ - 2.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-drchrono-oauth2.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2019 Eric Shelley
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.
@@ -0,0 +1,56 @@
1
+ # OmniAuth DrChrono OAuth2 Strategy
2
+
3
+ [![Build Status](https://travis-ci.org/bartimaeus/omniauth-drchrono-oauth2.svg?branch=master)](https://travis-ci.org/bartimaeus/omniauth-drchrono-oauth2)
4
+
5
+ A DrChrono OAuth2 strategy for OmniAuth.
6
+
7
+ For more details, read the DrChrono documentation: https://www.drchrono.com/api/
8
+
9
+ I found out after I pushed version 1 of this gem that another omniauth strategy already exists for DrChrono [https://github.com/johnnadeau/omniauth-drchrono](omniauth-drchrono). I renamed this project to `omniauth-drchrono-oauth2` to avoid confusion.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'omniauth-drchrono-oauth2'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install omniauth-drchrono-oauth2
24
+
25
+ ## Usage
26
+
27
+ Register your application with DrChrono to receive an API key: https://www.drchrono.com/api/
28
+
29
+ This is an example that you might put into a Rails initializer at `config/initializers/omniauth.rb`:
30
+
31
+ ```ruby
32
+ Rails.application.config.middleware.use OmniAuth::Builder do
33
+ provider :drchrono, ENV['DRCHRONO_CLIENT_ID'], ENV['DRCHRONO_CLIENT_SECRET'], :scope => 'user:read patients:read patients:summary:read'
34
+ end
35
+ ```
36
+
37
+ You can now access the OmniAuth DrChrono OAuth2 URL: `/auth/drchrono`.
38
+
39
+ ## Granting Member Permissions to Your Application
40
+
41
+ With the DrChrono API, you have the ability to specify which permissions you want users to grant your application.
42
+ For more details, read the DrChrono documentation: https://www.drchrono.com/api/
43
+
44
+ You can configure the scope option:
45
+
46
+ ```ruby
47
+ provider :drchrono, ENV['DRCHRONO_CLIENT_ID'], ENV['DRCHRONO_CLIENT_SECRET'], :scope => 'user:read'
48
+ ```
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'sinatra'
4
+ gem 'omniauth-drchrono-oauth2'
@@ -0,0 +1,31 @@
1
+ # Sample app for DrChrono OAuth2 Strategy
2
+ # Make sure to setup the ENV variables DRCHRONO_CLIENT_ID and DRCHRONO_CLIENT_SECRET
3
+ # Run with "bundle exec rackup"
4
+
5
+ require 'bundler/setup'
6
+ require 'sinatra/base'
7
+ require 'omniauth-drchrono'
8
+
9
+ class App < Sinatra::Base
10
+ get '/' do
11
+ redirect '/auth/drchrono'
12
+ end
13
+
14
+ get '/auth/:provider/callback' do
15
+ content_type 'application/json'
16
+ MultiJson.encode(request.env['omniauth.auth'])
17
+ end
18
+
19
+ get '/auth/failure' do
20
+ content_type 'application/json'
21
+ MultiJson.encode(request.env)
22
+ end
23
+ end
24
+
25
+ use Rack::Session::Cookie, :secret => 'change_me'
26
+
27
+ use OmniAuth::Builder do
28
+ provider :drchrono, ENV['DRCHRONO_CLIENT_ID'], ENV['DRCHRONO_CLIENT_SECRET'], scope: 'user:read'
29
+ end
30
+
31
+ run App.new
@@ -0,0 +1,2 @@
1
+ require "omniauth-drchrono-oauth2/version"
2
+ require "omniauth/strategies/drchrono"
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module DrChronoOauth2
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,76 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class DrChrono < OmniAuth::Strategies::OAuth2
6
+ option :name, 'drchrono'
7
+
8
+ option :client_options, {
9
+ :site => 'https://drchrono.com/api',
10
+ :authorize_url => 'https://drchrono.com/o/authorize',
11
+ :token_url => 'https://drchrono.com/o/token/'
12
+ }
13
+
14
+ option :scope, 'user:read'
15
+
16
+ uid do
17
+ raw_info['id']
18
+ end
19
+
20
+ info do
21
+ {
22
+ 'auth' => oauth2_access_token,
23
+ 'doctor' => doctor,
24
+ 'offices' => offices
25
+ }
26
+ end
27
+
28
+ extra do
29
+ {
30
+ 'raw_info' => raw_info
31
+ }
32
+ end
33
+
34
+ def callback_url
35
+ full_host + script_name + callback_path
36
+ end
37
+
38
+ alias :oauth2_access_token :access_token
39
+
40
+ def access_token
41
+ ::OAuth2::AccessToken.new(client, oauth2_access_token.token, {
42
+ :expires_in => oauth2_access_token.expires_in,
43
+ :expires_at => oauth2_access_token.expires_at
44
+ })
45
+ end
46
+
47
+ def raw_info
48
+ @raw_info ||= access_token.get(profile_endpoint).parsed
49
+ end
50
+
51
+ def doctor
52
+ @doctor ||= access_token.get(doctors_endpoint).parsed
53
+ end
54
+
55
+ def offices
56
+ @offices ||= access_token.get(offices_endpoint).parsed['results']
57
+ end
58
+
59
+ private
60
+
61
+ def profile_endpoint
62
+ '/users/current'
63
+ end
64
+
65
+ def doctors_endpoint
66
+ "/doctors/#{raw_info['doctor']}"
67
+ end
68
+
69
+ def offices_endpoint
70
+ '/offices'
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ OmniAuth.config.add_camelization 'drchrono', 'DrChrono'
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth-drchrono-oauth2/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "omniauth-drchrono-oauth2"
8
+ gem.version = OmniAuth::DrChronoOauth2::VERSION
9
+ gem.authors = ["Eric Shelley"]
10
+ gem.email = ["eric@webdesignbakery.com"]
11
+ gem.description = %q{DrChrono OAuth2 strategy for OmniAuth.}
12
+ gem.summary = %q{DrChrono OAuth2 strategy for OmniAuth.}
13
+ gem.homepage = "https://github.com/bartimaeus/omniauth-drchrono-oauth2"
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.2'
22
+
23
+ gem.add_development_dependency 'bundler', '~> 1.16'
24
+ gem.add_development_dependency 'rake', '~> 12.3'
25
+
26
+ gem.add_development_dependency 'rspec', '~> 3.6'
27
+ gem.add_development_dependency 'simplecov', '~> 0.16'
28
+ end
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-drchrono-oauth2'
3
+
4
+ describe OmniAuth::Strategies::DrChrono do
5
+ subject { OmniAuth::Strategies::DrChrono.new(nil) }
6
+
7
+ it 'adds camelization for itself' do
8
+ expect(OmniAuth::Utils.camelize('drchrono')).to eq('DrChrono')
9
+ end
10
+
11
+ describe '#client' do
12
+ it 'has correct DrChrono site' do
13
+ expect(subject.client.site).to eq('https://drchrono.com/api')
14
+ end
15
+
16
+ it 'has correct `authorize_url`' do
17
+ expect(subject.client.options[:authorize_url]).to eq('https://drchrono.com/o/authorize')
18
+ end
19
+
20
+ it 'has correct `token_url`' do
21
+ expect(subject.client.options[:token_url]).to eq('https://drchrono.com/o/token/')
22
+ end
23
+ end
24
+
25
+ describe '#callback_path' do
26
+ it 'has the correct callback path' do
27
+ expect(subject.callback_path).to eq('/auth/drchrono/callback')
28
+ end
29
+ end
30
+
31
+ describe '#uid' do
32
+ before :each do
33
+ allow(subject).to receive(:raw_info) { Hash['id' => 'uid'] }
34
+ end
35
+
36
+ it 'returns the id from raw_info' do
37
+ expect(subject.uid).to eq('uid')
38
+ end
39
+ end
40
+
41
+ describe '#info / #raw_info' do
42
+ let(:access_token) { instance_double OAuth2::AccessToken }
43
+
44
+ let(:parsed_response) { Hash['doctor' => 14234, 'id' => 43456, 'is_doctor' => true, 'is_staff' => false, 'practice_group' => 8765544, 'username' => 'drchrono'] }
45
+
46
+ let(:doctors_endpoint) { "/doctors/14234" }
47
+ let(:offices_endpoint) { '/offices' }
48
+ let(:profile_endpoint) { '/users/current' }
49
+
50
+ let(:doctors_response) { instance_double OAuth2::Response, parsed: parsed_response }
51
+ let(:offices_response) { instance_double OAuth2::Response, parsed: parsed_response }
52
+ let(:profile_response) { instance_double OAuth2::Response, parsed: parsed_response }
53
+
54
+ before :each do
55
+ allow(subject).to receive(:access_token).and_return access_token
56
+
57
+ allow(access_token).to receive(:get)
58
+ .with(doctors_endpoint)
59
+ .and_return(doctors_response)
60
+
61
+ allow(access_token).to receive(:get)
62
+ .with(offices_endpoint)
63
+ .and_return(offices_response)
64
+
65
+ allow(access_token).to receive(:get)
66
+ .with(profile_endpoint)
67
+ .and_return(profile_response)
68
+ end
69
+
70
+ it 'returns parsed responses using access token' do
71
+ expect(subject.info).to have_key 'auth'
72
+ expect(subject.info).to have_key 'doctor'
73
+ expect(subject.info).to have_key 'offices'
74
+
75
+ expect(subject.raw_info['doctor']).to eq(14234)
76
+ expect(subject.raw_info['id']).to eq(43456)
77
+ expect(subject.raw_info['is_doctor']).to be_truthy
78
+ expect(subject.raw_info['is_staff']).to be_falsey
79
+ expect(subject.raw_info['practice_group']).to eq(8765544)
80
+ expect(subject.raw_info['username']).to eq('drchrono')
81
+ end
82
+ end
83
+
84
+ describe '#extra' do
85
+ let(:raw_info) { Hash[:foo => 'bar'] }
86
+
87
+ before :each do
88
+ allow(subject).to receive(:raw_info).and_return raw_info
89
+ end
90
+
91
+ specify { expect(subject.extra['raw_info']).to eq raw_info }
92
+ end
93
+
94
+ describe '#access_token' do
95
+ let(:expires_in) { 3600 }
96
+ let(:expires_at) { 946688400 }
97
+ let(:token) { 'token' }
98
+ let(:access_token) do
99
+ instance_double OAuth2::AccessToken, :expires_in => expires_in,
100
+ :expires_at => expires_at, :token => token
101
+ end
102
+
103
+ before :each do
104
+ allow(subject).to receive(:oauth2_access_token).and_return access_token
105
+ end
106
+
107
+ specify { expect(subject.access_token.expires_in).to eq expires_in }
108
+ specify { expect(subject.access_token.expires_at).to eq expires_at }
109
+ end
110
+
111
+ describe '#authorize_params' do
112
+ describe 'scope' do
113
+ before :each do
114
+ allow(subject).to receive(:session).and_return({})
115
+ end
116
+
117
+ it 'sets default scope' do
118
+ expect(subject.authorize_params['scope']).to eq('user:read')
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,19 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ # This file was generated by the `rspec --init` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # Require this file using `require "spec_helper"` to ensure that it is only
7
+ # loaded once.
8
+ #
9
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
10
+ RSpec.configure do |config|
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = 'random'
19
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-drchrono-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric Shelley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.16'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.16'
83
+ description: DrChrono OAuth2 strategy for OmniAuth.
84
+ email:
85
+ - eric@webdesignbakery.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - example/Gemfile
98
+ - example/config.ru
99
+ - lib/omniauth-drchrono-oauth2.rb
100
+ - lib/omniauth-drchrono-oauth2/version.rb
101
+ - lib/omniauth/strategies/drchrono.rb
102
+ - omniauth-drchrono-oauth2.gemspec
103
+ - spec/omniauth/strategies/drchrono_spec.rb
104
+ - spec/spec_helper.rb
105
+ homepage: https://github.com/bartimaeus/omniauth-drchrono-oauth2
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.5.2.3
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: DrChrono OAuth2 strategy for OmniAuth.
129
+ test_files:
130
+ - spec/omniauth/strategies/drchrono_spec.rb
131
+ - spec/spec_helper.rb