omniauth-prestodoctor 0.5.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.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.rspec +1 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +74 -0
- data/Rakefile +8 -0
- data/lib/omniauth-prestodoctor.rb +2 -0
- data/lib/omniauth-prestodoctor/version.rb +5 -0
- data/lib/omniauth/strategies/prestodoctor.rb +54 -0
- data/omniauth-prestodoctor.gemspec +26 -0
- data/spec/omniauth/strategies/prestodoctor_spec.rb +21 -0
- data/spec/spec_helper.rb +18 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 29dbe24561580e63333f17ac1015c4a3175b6e87
|
4
|
+
data.tar.gz: 030f7531763ffc4b3c87376248a1b61525f0f387
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d750ae39dae3424c359853c4d47779a10e7bb35ff37cf780cb52e39b8445e6ac23f490ff44da6e15c1a96db4ad302c09e90eb78be91bf8fdf291d2c0faed2d2
|
7
|
+
data.tar.gz: 78ceb5d1e2303b23650406d9f57c52021e4cb8081247743f434b6ed3dc69f40fea742ab082f7fd01c7c31f2b9e89f71aa934bac477152e0cd442d41d5b2af67a
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015, Kyle Powers - PrestoDoctor
|
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,74 @@
|
|
1
|
+
# OmniAuth PrestoDoctor Strategy
|
2
|
+
|
3
|
+
OmniAuth 2 strategy for [PrestoDoctor](https://prestodoctor.com/)
|
4
|
+
|
5
|
+
For more details, read the [PrestoDoctor API Reference](https://prestodoctor.com/docs)
|
6
|
+
|
7
|
+
# Installation
|
8
|
+
|
9
|
+
Add to your Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem "omniauth-prestodoctor"
|
13
|
+
```
|
14
|
+
|
15
|
+
then bundle install
|
16
|
+
|
17
|
+
# Usage & Configuration
|
18
|
+
|
19
|
+
Here's an example, adding the middleware to a Rails app in config/initializers/omniauth.rb:
|
20
|
+
|
21
|
+
You can configure permissions/scope (as a space separated string),
|
22
|
+
which you pass in to the `provider` method after your `PRESTO_APP_ID` and `PRESTO_SECRET`:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
26
|
+
provider :presto_doctor, ENV['PRESTO_APP_ID'], ENV['PRESTO_SECRET'], scope: 'user_info recommendation photo_id'
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
Available scopes are:
|
31
|
+
|
32
|
+
- `user_info`
|
33
|
+
- `recommendation`
|
34
|
+
- `photo_id`
|
35
|
+
|
36
|
+
If you don't include any `scope` it will default to only `user_info`.
|
37
|
+
|
38
|
+
NOTE: While developing your application, if you change the scope in the initializer you will need to restart your app server.
|
39
|
+
|
40
|
+
You can now access the OmniAuth PrestoDoctor OAuth2 URL: /auth/prestodoctor
|
41
|
+
|
42
|
+
# Usage with Devise
|
43
|
+
|
44
|
+
In your app/initializers/devise.rb, in the omniauth section, add a line using similar syntax and configuration:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
config.omniauth :presto_doctor, ENV['PRESTO_APP_ID'], ENV['PRESTO_SECRET'], scope: 'user_info recommendation photo_id'
|
48
|
+
```
|
49
|
+
|
50
|
+
## Add to your User model
|
51
|
+
|
52
|
+
For a user to be able to log in via PrestoDoctor, you will need to set on your User model:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
devise :omniauthable, :omniauth_providers => [:prestodoctor]
|
56
|
+
```
|
57
|
+
|
58
|
+
## Including in Views
|
59
|
+
|
60
|
+
You will now be able to link to the PrestoDoctor authorization path, like so:
|
61
|
+
|
62
|
+
```erb
|
63
|
+
<%= link_to user_omniauth_authorize_path(:prestodoctor) do %>
|
64
|
+
<%= image_tag 'prestodoctor-login.png' %>
|
65
|
+
<% end %>
|
66
|
+
```
|
67
|
+
|
68
|
+
# Callbacks
|
69
|
+
|
70
|
+
You will need to set up a callback path that we can call with the generated token
|
71
|
+
|
72
|
+
You can see an example of this here: https://github.com/PrestoDoctor/prestodoctor-oauth
|
73
|
+
|
74
|
+
(look at `app/controllers/users/omniauth/callbacks_controller.rb` and it's related entry in `routes.rb`)
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class PrestoDoctor < OmniAuth::Strategies::OAuth2
|
6
|
+
BASE_USER_API = '/api/v1/user'
|
7
|
+
SCOPES = {
|
8
|
+
USER_INFO: 'user_info',
|
9
|
+
RECOMMENDATION: 'recommendation',
|
10
|
+
PHOTO_ID: 'photo_id'
|
11
|
+
}
|
12
|
+
|
13
|
+
option :name, :prestodoctor
|
14
|
+
|
15
|
+
option :client_options, {
|
16
|
+
site: 'https://prestodoctor.com',
|
17
|
+
authorize_url: '/oauth/authorize'
|
18
|
+
}
|
19
|
+
|
20
|
+
uid { raw_info['id'] }
|
21
|
+
|
22
|
+
info do
|
23
|
+
raw_info
|
24
|
+
end
|
25
|
+
|
26
|
+
extra do
|
27
|
+
{
|
28
|
+
recommendation: recommendation,
|
29
|
+
photo_id: photo_id
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def raw_info
|
34
|
+
@raw_info ||= has_scope?(SCOPES[:USER_INFO]) ? access_token.get(BASE_USER_API).parsed : nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def recommendation
|
38
|
+
@raw_rec ||= has_scope?(SCOPES[:RECOMMENDATION]) ? access_token.get(BASE_USER_API + '/recommendation').parsed : nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def photo_id
|
42
|
+
@raw_photo_id ||= has_scope?(SCOPES[:PHOTO_ID]) ? access_token.get(BASE_USER_API + '/photo_id').parsed : nil
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def has_scope?(scope_name)
|
48
|
+
return false unless access_token.params['scope']
|
49
|
+
scopes = access_token.params['scope'].split(' ')
|
50
|
+
scopes.include? scope_name
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "omniauth-prestodoctor/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "omniauth-prestodoctor"
|
7
|
+
s.version = OmniAuth::PrestoDoctor::VERSION
|
8
|
+
s.authors = ["Kyle Powers"]
|
9
|
+
s.email = ["kyle@prestodoctor.com"]
|
10
|
+
s.homepage = "https://github.com/PrestoDoctor/omniauth-prestodoctor"
|
11
|
+
s.summary = %q{OmniAuth strategy for PrestoDoctor}
|
12
|
+
s.description = %q{OmniAuth strategy for PrestoDoctor}
|
13
|
+
s.licenses = ['MIT']
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency 'multi_json', '~> 1.3'
|
21
|
+
s.add_runtime_dependency 'omniauth-oauth2', '~> 1.2'
|
22
|
+
s.add_development_dependency 'rspec', '~> 2.7'
|
23
|
+
s.add_development_dependency 'rack-test', '~> 0.6'
|
24
|
+
s.add_development_dependency 'simplecov', '~> 0.10'
|
25
|
+
s.add_development_dependency 'webmock', '~> 1.20'
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniAuth::Strategies::PrestoDoctor do
|
4
|
+
subject do
|
5
|
+
OmniAuth::Strategies::PrestoDoctor.new({})
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'client options' do
|
9
|
+
it 'should have correct name' do
|
10
|
+
expect(subject.options.name).to eq(:prestodoctor)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should have correct site' do
|
14
|
+
expect(subject.options.client_options.site).to eq('https://prestodoctor.com')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have correct authorize url' do
|
18
|
+
expect(subject.options.client_options.authorize_url).to eq('/oauth/authorize')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.unshift File.expand_path('..', __FILE__)
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
require 'rspec'
|
6
|
+
require 'rack/test'
|
7
|
+
require 'webmock/rspec'
|
8
|
+
require 'omniauth'
|
9
|
+
require 'omniauth-prestodoctor'
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.include WebMock::API
|
13
|
+
config.include Rack::Test::Methods
|
14
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
15
|
+
config.expect_with :rspec do |c|
|
16
|
+
c.syntax = :expect
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-prestodoctor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kyle Powers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multi_json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
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.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack-test
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.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.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.20'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.20'
|
97
|
+
description: OmniAuth strategy for PrestoDoctor
|
98
|
+
email:
|
99
|
+
- kyle@prestodoctor.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- lib/omniauth-prestodoctor.rb
|
111
|
+
- lib/omniauth-prestodoctor/version.rb
|
112
|
+
- lib/omniauth/strategies/prestodoctor.rb
|
113
|
+
- omniauth-prestodoctor.gemspec
|
114
|
+
- spec/omniauth/strategies/prestodoctor_spec.rb
|
115
|
+
- spec/spec_helper.rb
|
116
|
+
homepage: https://github.com/PrestoDoctor/omniauth-prestodoctor
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.4.5
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: OmniAuth strategy for PrestoDoctor
|
140
|
+
test_files:
|
141
|
+
- spec/omniauth/strategies/prestodoctor_spec.rb
|
142
|
+
- spec/spec_helper.rb
|