omniauth-digitalocean 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7a2026f9593fd5db82cbc423791d3d677075ecea
4
+ data.tar.gz: 2170318d211223151e5aab533e1bb2cee4d7a45e
5
+ SHA512:
6
+ metadata.gz: 45c610ff7a46f2a066f2043db9d6d9600081bdd7c3ebd99f1233f72f5cbbcb7f7ebf3fd7e9b98d03a2c717ec0c025b19c205c5c907bf8491aaa7f2c8c078a005
7
+ data.tar.gz: 114836396c8bd959a8fd23241824270edac9b3631ad80d389a5c398de420ada5d67330fc0658b3348c0cd0b55608370a58151e7609882ea8d76a48e056a0c754
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-digitalocean.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Phillip Baker
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,45 @@
1
+ # DigitalOcean's Omniauth strategy
2
+
3
+ This is the official Ruby OmniAuth strategy for authenticating to [DigitalOcean](https://www.digitalocean.com).
4
+
5
+ Before you can start developing your API client for DigitalOcean, you need to create an application on your account and copy the application id and secret.
6
+
7
+ ## Installation
8
+
9
+ Add the strategy to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'omniauth-digitalocean'
13
+ ```
14
+
15
+ And bundle.
16
+
17
+ ## Usage
18
+
19
+ You can integrate the strategy into your middleware in a `config.ru`:
20
+
21
+ ```ruby
22
+ use OmniAuth::Builder do
23
+ provider :digitalocean, SETTINGS['CLIENT_ID'], SETTINGS['CLIENT_SECRET'], scope: "read write"
24
+ end
25
+ ```
26
+
27
+ If you're using Rails, you'll want to add to the middleware stack:
28
+
29
+ ```ruby
30
+ Rails.application.config.middleware.use OmniAuth::Builder do
31
+ provider :digitalocean, SETTINGS['CLIENT_ID'], SETTINGS['CLIENT_SECRET'], scope: "read write"
32
+ end
33
+ ```
34
+
35
+ - The scope needs to be separated by space and not comma: "public redeploy" instead of "public,redeploy" !
36
+
37
+ For additional information, refer to the [OmniAuth wiki](https://github.com/intridea/omniauth/wiki).
38
+
39
+ See the [example](https://github.com/digitaloceancloud/omniauth-digitalocean/blob/master/example/sinatra/config.ru) Sinatra app for full examples
40
+
41
+ Note: before running example app, please add your applicaation id and secret to ` example/config.ru ` file.
42
+
43
+ ## License
44
+
45
+ omniauth-digitalocean is released under the MIT License.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ desc "Run specs"
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc "Default: run specs."
8
+ task :default => :spec
9
+ task :test => :spec
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'sinatra'
4
+ gem 'omniauth'
5
+ gem 'omniauth-digitalocean', :path => '../../'
6
+ gem 'multi_json'
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'sinatra'
4
+ require 'omniauth-digitalocean'
5
+
6
+ get '/' do
7
+ redirect '/auth/digitalocean'
8
+ end
9
+
10
+ get '/auth/:provider/callback' do
11
+ content_type 'text/plain'
12
+ request.env['omniauth.auth'].to_hash.inspect rescue "No Data"
13
+ end
14
+
15
+ get '/auth/failure' do
16
+ content_type 'text/plain'
17
+ request.env['omniauth.auth'].to_hash.inspect rescue "No Data"
18
+ end
19
+
20
+ use Rack::Session::Cookie
21
+
22
+ use OmniAuth::Builder do
23
+ provider :digitalocean, "2431aea9301744c9243e5777d31d6375cd4d8673f86569e125ad880b8f4f38b3", "a5e779f88e6f8053f400fb917aaa3cf89f23e2f72d85f3e375ebc02b93153787", scope: "read write"
24
+ end
@@ -0,0 +1,70 @@
1
+ require 'omniauth-oauth2'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to DigitalOcean via OAuth and retrieve basic user information.
8
+ # Usage:
9
+ # use OmniAuth::Strategies::Digitalocean, 'consumerkey', 'consumersecret', :scope => 'read write', :display => 'plain'
10
+ #
11
+ class Digitalocean < OmniAuth::Strategies::OAuth2
12
+ AUTHENTICATION_PARAMETERS = %w(display state scope)
13
+ BASE_URL = "https://cloud.digitalocean.com"
14
+
15
+ option :name, :digitalocean
16
+
17
+ unless OmniAuth.config.test_mode
18
+ option :client_options, {
19
+ :authorize_url => "#{BASE_URL}/v1/oauth/authorize",
20
+ :token_url => "#{BASE_URL}/v1/oauth/token",
21
+ :site => BASE_URL
22
+ }
23
+ else
24
+ option :client_options, {
25
+ :authorize_url => "http://localhost:3000/v1/oauth/authorize",
26
+ :token_url => "http://localhost:3000/v1/oauth/token",
27
+ :site => "http://localhost:3000"
28
+ }
29
+ end
30
+
31
+ option :authorize_options, AUTHENTICATION_PARAMETERS
32
+
33
+ uid do
34
+ access_token.params['uid']
35
+ end
36
+
37
+ info do
38
+ access_token.params['info']
39
+ end
40
+
41
+ # Hook useful for appending parameters into the auth url before sending
42
+ # to provider.
43
+ def request_phase
44
+ super
45
+ end
46
+
47
+ # Hook used after response with code from provider. Used to prep token
48
+ # request from provider.
49
+ def callback_phase
50
+ super
51
+ end
52
+
53
+ ##
54
+ # You can pass +display+, +state+ or +scope+ params to the auth request, if
55
+ # you need to set them dynamically. You can also set these options
56
+ # in the OmniAuth config :authorize_params option.
57
+ #
58
+ # /v1/auth/digialocean?display=fancy&state=ABC
59
+ #
60
+ def authorize_params
61
+ super.tap do |params|
62
+ AUTHENTICATION_PARAMETERS.each do |v|
63
+ params[v.to_sym] = request.params[v] if request.params[v]
64
+ end
65
+ end
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Digitalocean
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-digitalocean/version"
2
+ require "omniauth/strategies/digitalocean"
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'omniauth-digitalocean/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "omniauth-digitalocean"
7
+ spec.version = Omniauth::Digitalocean::VERSION
8
+ spec.authors = ["Phillip Baker"]
9
+ spec.email = ["phillip@digitalocean.com"]
10
+ spec.summary = %q{Oauth2 strategy for authentication via DO.}
11
+ spec.description = %q{Write a longer description. Optional.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "omniauth", "~> 1.0"
21
+ spec.add_dependency "omniauth-oauth2", "~> 1.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec", "~> 2.7"
26
+ spec.add_development_dependency "rack-test"
27
+ spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency "webmock"
29
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::DigitalOcean do
4
+ subject do
5
+ OmniAuth::Strategies::DigitalOcean.new({})
6
+ end
7
+
8
+ context "client options" do
9
+ it { expect(subject.options.name).to eq(:digitalocean) }
10
+
11
+ it { expect(subject.options.client_options.site).to eq("https://cloud.digitalocean.com") }
12
+ it { expect(subject.options.client_options.authorize_url).to eq("https://cloud.digitalocean.com/v1/oauth/authorize") }
13
+ it { expect(subject.options.client_options.token_url).to eq("https://cloud.digitalocean.com/v1/oauth/token") }
14
+ end
15
+
16
+ end
@@ -0,0 +1,22 @@
1
+ require 'rspec'
2
+ require 'rack/test'
3
+ require 'webmock/rspec'
4
+ require 'omniauth'
5
+ require 'omniauth-digitalocean'
6
+
7
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
8
+ RSpec.configure do |config|
9
+ config.treat_symbols_as_metadata_keys_with_true_values = true
10
+ config.run_all_when_everything_filtered = true
11
+ config.filter_run :focus
12
+
13
+ config.include WebMock::API
14
+ config.include Rack::Test::Methods
15
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
16
+
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
22
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-digitalocean
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Phillip Baker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-22 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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
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: simplecov
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: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Write a longer description. Optional.
126
+ email:
127
+ - phillip@digitalocean.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - Gemfile
134
+ - LICENSE.txt
135
+ - README.md
136
+ - Rakefile
137
+ - examples/sinatra/Gemfile
138
+ - examples/sinatra/config.ru
139
+ - lib/omniauth-digitalocean.rb
140
+ - lib/omniauth-digitalocean/version.rb
141
+ - lib/omniauth/strategies/digitalocean.rb
142
+ - omniauth-digitalocean.gemspec
143
+ - spec/omniauth/strategies/digitalocean_spec.rb
144
+ - spec/spec_helper.rb
145
+ homepage: ''
146
+ licenses:
147
+ - MIT
148
+ metadata: {}
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 2.2.0
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: Oauth2 strategy for authentication via DO.
169
+ test_files:
170
+ - spec/omniauth/strategies/digitalocean_spec.rb
171
+ - spec/spec_helper.rb