omniauth-netlify 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 760c11b53c5c2fb11976ef3cbad273189c1f00efc55c005c47c87a94809fcb03
4
+ data.tar.gz: 167d66b23f5a915f260647f4e3465c230d2730943d3e880d6ef199c4227ba5df
5
+ SHA512:
6
+ metadata.gz: 3d90c0b3a375d67427f5ce25d7db2945b8033d0e2886902b1b03b49ab23b5ac020fb1c1a8961a90cf8d83fe0618a0ef5176723fde22c3ff71f88ccd745ecbb3b
7
+ data.tar.gz: 47887a15b656b0345f79b3f75b2be0f829634bd6dac93b2e77cee15aab2f94e070cc0f67de4bb171ceb095e8fca944109979eb6eff66b217c2cbc7875a0e119c
@@ -0,0 +1,22 @@
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
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
@@ -0,0 +1,10 @@
1
+ ---
2
+ inherit_gem:
3
+ rubocop-fnando: .rubocop.yml
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.6
7
+
8
+ Naming/FileName:
9
+ Exclude:
10
+ - lib/omniauth-netlify.rb
@@ -0,0 +1,17 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ sudo: false
5
+ notifications:
6
+ email: false
7
+ rvm:
8
+ - 2.7.0
9
+ before_script:
10
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
11
+ - chmod +x ./cc-test-reporter
12
+ - "./cc-test-reporter before-build"
13
+ after_script:
14
+ - "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
15
+ env:
16
+ global:
17
+ secure: dfXiSvrQwumUtZiGede/oD3XvTII6tvkPJ6mMKkl/g1npMAt6bCvFiZv5Gm2SiY5mbBT3q2uMsSCJ2w1gX3qIw7IzIzkr8jTn/jW3nBeHZu8Z5Egi77i5847/otClA/38FYlrVUFVfvXD2t9es4eeJwsN2lX6p5yaG606lrZxQxVqQFblo9oBsBZNjSoRKe0SZeJ1RUQlppJdr/GllSbpVW4p06Ifr2cslpNmMwREdqc6ftadjS8MzfZabpE8Y8ONtPKilPCu9R99u4OH51+jkkd1ukXTK+Ks+O3m/xECBOMUlzGFiY8VEafJFiJ1i9bkufW5gm0olRgr6yXsTRiOHsuwLEpyVOFD0QmX7YccS8iDsgtXq4RVQqNZ0a7/vGPrsqvdWoyp9dM9dX+9XyR7k3AZOMXAaR16iUaXi2IAJ1P7pVtj+ta3nfQdJOVEJGIkCJf/k8rniXWLoi9yTGyAFe/r/SebkgRDivEXTU8vIvsqrcHRtVkOKuU9zKOKIJICCgV0QBhTbIM2T/pfhC5B6nANXQyCRnS0fQbOXWTecD0P6smgDrFAqVX/vtkKKGvVVzkzfMc5lCnSAcYNz7CRvu2KSWAWnC6gFSYF9Y5vrdVjWSxcYP1pkILhuc98uV9XDatA9gEeo6HQ8TLDIQkA9AmDWtTtWoCt6SYaJZ6AVY=
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in omniauth-citrix.gemspec
6
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2019 Nando Vieira
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,49 @@
1
+ # Omniauth::Netlify
2
+
3
+ [![Travis-CI](https://travis-ci.org/fnando/omniauth-netlify.svg)](https://travis-ci.org/fnando/omniauth-netlify)
4
+ [![CodeClimate](https://codeclimate.com/github/fnando/omniauth-netlify.svg)](https://codeclimate.com/github/fnando/omniauth-netlify)
5
+ [![Test Coverage](https://codeclimate.com/github/fnando/omniauth-netlify/badges/coverage.svg)](https://codeclimate.com/github/fnando/omniauth-netlify/coverage)
6
+ [![Gem](https://img.shields.io/gem/v/omniauth-netlify.svg)](https://rubygems.org/gems/omniauth-netlify)
7
+ [![Gem](https://img.shields.io/gem/dt/omniauth-netlify.svg)](https://rubygems.org/gems/omniauth-netlify)
8
+
9
+ [Netlify](http://netlify.com)'s OAuth2 Strategy for OmniAuth.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'omniauth-netlify'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install omniauth-netlify
24
+
25
+ ## Usage
26
+
27
+ `OmniAuth::Strategies::Netlify` is simply a Rack middleware. Read the OmniAuth docs for detailed instructions: <https://github.com/intridea/omniauth>.
28
+
29
+ First, create a new application at `https://app.netlify.com/user/applications#oauth`. Your callback URL must be something like `https://example.com/auth/netlify/callback`. For development you can use `http://127.0.0.1:3000/auth/netlify/callback`.
30
+
31
+ Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`. This example assumes you're exporting your credentials as environment variables.
32
+
33
+ ```ruby
34
+ Rails.application.config.middleware.use OmniAuth::Builder do
35
+ provider :netlify,
36
+ ENV['NETLIFY_CLIENT_ID'],
37
+ ENV['NETLIFY_CLIENT_SECRET']
38
+ end
39
+ ```
40
+
41
+ Now visit `/auth/netlify` to start authentication against Netlify.
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork [omniauth-netlify](https://github.com/fnando/omniauth-netlify/fork)
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create a new Pull Request
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+ require "rubocop/rake_task"
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << "test"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ t.warning = false
11
+ end
12
+
13
+ RuboCop::RakeTask.new
14
+
15
+ task default: %i[test rubocop]
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omniauth-netlify/version"
4
+ require "omniauth/strategies/netlify"
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Omniauth
4
+ module Netlify
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omniauth"
4
+ require "omniauth-oauth2"
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ class Netlify < OmniAuth::Strategies::OAuth2
9
+ option :name, "netlify"
10
+
11
+ option :client_options,
12
+ authorize_url: "https://app.netlify.com/authorize",
13
+ token_url: "https://api.netlify.com/oauth/token"
14
+
15
+ def authorize_params
16
+ super.tap do |params|
17
+ params[:client_id] = client.id
18
+ params[:redirect_uri] ||= callback_url
19
+ end
20
+ end
21
+
22
+ uid do
23
+ info[:id]
24
+ end
25
+
26
+ info do
27
+ {
28
+ id: raw_info.fetch(:id),
29
+ email: raw_info.fetch(:email),
30
+ name: raw_info.fetch(:full_name)
31
+ }
32
+ end
33
+
34
+ extra do
35
+ raw_info
36
+ end
37
+
38
+ def token_params
39
+ OmniAuth::Strategy::Options.new(
40
+ code: request.params["code"],
41
+ redirect_uri: callback_url,
42
+ client_id: client.id,
43
+ client_secret: client.secret,
44
+ type: "web_server"
45
+ )
46
+ end
47
+
48
+ def raw_info
49
+ @raw_info ||= deep_symbolize(
50
+ access_token.get("https://api.netlify.com/api/v1/user").parsed
51
+ )
52
+ end
53
+
54
+ def callback_url
55
+ full_host + script_name + callback_path
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "./lib/omniauth-netlify/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "omniauth-netlify"
7
+ spec.version = Omniauth::Netlify::VERSION
8
+ spec.authors = ["Nando Vieira"]
9
+ spec.email = ["fnando.vieira@gmail.com"]
10
+ spec.summary = "OmniAuth strategy for Netlify (https://netlify.com)."
11
+ spec.description = spec.summary
12
+ spec.homepage = "https://github.com/fnando/omniauth-netlify"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
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_runtime_dependency "omniauth-oauth2"
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "minitest-utils"
23
+ spec.add_development_dependency "mocha"
24
+ spec.add_development_dependency "pry-meta"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rubocop"
27
+ spec.add_development_dependency "rubocop-fnando"
28
+ spec.add_development_dependency "simplecov"
29
+ spec.add_development_dependency "webmock"
30
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class ClientOptionsTest < Minitest::Test
6
+ let(:app) { ->(env) { } }
7
+
8
+ let(:strategy) do
9
+ OmniAuth::Strategies::Netlify.new(app, "consumer_id", "consumer_secret")
10
+ end
11
+
12
+ test "sets name" do
13
+ assert_equal "netlify", strategy.options.name
14
+ end
15
+
16
+ test "sets authorize url" do
17
+ assert_equal "https://app.netlify.com/authorize",
18
+ strategy.options.client_options.authorize_url
19
+ end
20
+
21
+ test "sets token url" do
22
+ assert_equal "https://api.netlify.com/oauth/token",
23
+ strategy.options.client_options.token_url
24
+ end
25
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class DataTest < Minitest::Test
6
+ let(:app) { ->(env) { } }
7
+
8
+ let(:strategy) do
9
+ OmniAuth::Strategies::Netlify.new(app, "consumer_id", "consumer_secret")
10
+ end
11
+
12
+ test "returns raw info" do
13
+ payload = {"id" => "ID"}
14
+ access_token = mock("access_token")
15
+ response = mock("response", parsed: payload)
16
+ access_token
17
+ .expects(:get)
18
+ .with("https://api.netlify.com/api/v1/user")
19
+ .returns(response)
20
+ strategy.stubs(:access_token).returns(access_token)
21
+
22
+ assert_equal Hash[:id, "ID"], strategy.raw_info
23
+ end
24
+
25
+ test "returns info" do
26
+ raw_info = {id: "ID", full_name: "NAME", email: "EMAIL"}
27
+ strategy.stubs(:raw_info).returns(raw_info)
28
+
29
+ info = strategy.info
30
+
31
+ assert_equal "ID", info[:id]
32
+ assert_equal "NAME", info[:name]
33
+ assert_equal "EMAIL", info[:email]
34
+ end
35
+
36
+ test "returns uid" do
37
+ strategy.stubs(:info).returns(id: "ID")
38
+ assert_equal "ID", strategy.uid
39
+ end
40
+
41
+ test "returns extra info" do
42
+ raw_info = {raw: true}
43
+ strategy.stubs(:raw_info).returns(raw_info)
44
+
45
+ assert_equal raw_info, strategy.extra
46
+ end
47
+
48
+ test "returns authorize params" do
49
+ session = {}
50
+ request = Rack::Request.new("env.session" => {})
51
+ strategy.stubs(:session).returns(session)
52
+ strategy.stubs(:request).returns(request)
53
+ strategy.stubs(:script_name).returns("")
54
+
55
+ assert_equal "consumer_id", strategy.authorize_params.client_id
56
+ assert_equal "/auth/netlify/callback",
57
+ strategy.authorize_params.redirect_uri
58
+ end
59
+
60
+ test "returns token params" do
61
+ strategy.stubs(:callback_url).returns("/auth/netlify/callback")
62
+ strategy.request.stubs(:params).returns("code" => "CODE")
63
+
64
+ assert_equal "CODE", strategy.token_params.code
65
+ assert_equal "/auth/netlify/callback", strategy.token_params.redirect_uri
66
+ assert_equal "consumer_id", strategy.token_params.client_id
67
+ assert_equal "consumer_secret", strategy.token_params.client_secret
68
+ assert_equal "web_server", strategy.token_params.type
69
+ end
70
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "simplecov"
4
+ SimpleCov.start
5
+
6
+ require "bundler/setup"
7
+ require "omniauth-netlify"
8
+
9
+ require "minitest/utils"
10
+ require "minitest/autorun"
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-netlify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nando Vieira
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-01-14 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-utils
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
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: pry-meta
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: rake
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: rubocop
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: rubocop-fnando
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
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: OmniAuth strategy for Netlify (https://netlify.com).
154
+ email:
155
+ - fnando.vieira@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rubocop.yml"
162
+ - ".travis.yml"
163
+ - Gemfile
164
+ - LICENSE.txt
165
+ - README.md
166
+ - Rakefile
167
+ - lib/omniauth-netlify.rb
168
+ - lib/omniauth-netlify/version.rb
169
+ - lib/omniauth/strategies/netlify.rb
170
+ - omniauth-netlify.gemspec
171
+ - test/omniauth/strategies/client_options_test.rb
172
+ - test/omniauth/strategies/data_test.rb
173
+ - test/test_helper.rb
174
+ homepage: https://github.com/fnando/omniauth-netlify
175
+ licenses:
176
+ - MIT
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubygems_version: 3.1.2
194
+ signing_key:
195
+ specification_version: 4
196
+ summary: OmniAuth strategy for Netlify (https://netlify.com).
197
+ test_files:
198
+ - test/omniauth/strategies/client_options_test.rb
199
+ - test/omniauth/strategies/data_test.rb
200
+ - test/test_helper.rb