omniauth-wp 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: bbfd0be2c2144d1fcd188b7d9be9302747b565456d66589c866d12aa2b0cac9a
4
+ data.tar.gz: f64394750966de7a75a95a88a014bce90dba6319a4b6aa339417bf8df26b9f43
5
+ SHA512:
6
+ metadata.gz: 8f4baa7adc2f19a2c212198412f29d5cf32b5e9a8108e297f45f9196a2a9808b02f5d4fe946869f164a6509e2597cb0984b77de2e7480fc0663b44024144d51c
7
+ data.tar.gz: 63c3c35e9ca577fe8af2805e9871404a46b7c4a4a20b3a9a24058fac786f96fbe26873873aa62be452b4d998f76b4a8b0fa4eae2a46a775d14ffa9acd212b654
@@ -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,11 @@
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-wordpress.rb
11
+ - lib/omniauth-wp.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: SECOgQFxKBTz1mpzWkz0ud5im4fsW7GrV/8ugeTcynWnJXcB3SFgfFIiOaW43x0LG8OWfp0GL6kGItXa5yQSD1xEWC3Ml1hhagevn++7y4v8yepvkgY9W96DmprfMAtBS6Qf+Xo9nMcmPSZa+b24zijPsG0uwUPogv6CJd9R50pO0cAC+7L3MTGTcLXe6MBzyE0gp3hPEXuHGU1HTR25ZOmllHO2alQfHbLJo13Y/0MFLL4JSadE6LnnSbYkupHJPQJgz4IvldtK/2mUJcVYqroeD5UyUjKb3lIu5TwMgSrAq+VNhWavcqG3v1/rRjBFzJCVaQ7dke3OgkNEdDge/8IR6tQx55fhR8TqLtoVLtVK38wlR6Nfan0TXEMZ87htf2ovbRRUhuHnxWG9wvfl09hNfkV2RfhJryAzWW2aVu2bBahVOwEInKacVAjknsA9LCYrhA6HUGokn9Q7K/YJu8q8+ueSf4q/4uE5f8rr+dBBqju+V8LCOOmA6/VEU7K7rsNUyGkBKKYzymmXyEyRD7tb1KZG8ofDxyHdiPiNXYCOvaXKl9hcuR4QSBQoP7k7SJpUojLbdpUIwMKEthmnx/lDGrRLn8Y0dZoXlMg+38/Gt5gDaaYxQgZpAretcbtPvYP3MQhPYDWuABNeHbgGZwKC2FN1JxjFikZEgdVBmQ8=
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::Wordpress
2
+
3
+ [![Travis-CI](https://travis-ci.org/fnando/omniauth-wp.svg)](https://travis-ci.org/fnando/omniauth-wp)
4
+ [![CodeClimate](https://codeclimate.com/github/fnando/omniauth-wp.svg)](https://codeclimate.com/github/fnando/omniauth-wp)
5
+ [![Test Coverage](https://codeclimate.com/github/fnando/omniauth-wp/badges/coverage.svg)](https://codeclimate.com/github/fnando/omniauth-wp/coverage)
6
+ [![Gem](https://img.shields.io/gem/v/omniauth-wp.svg)](https://rubygems.org/gems/omniauth-wp)
7
+ [![Gem](https://img.shields.io/gem/dt/omniauth-wp.svg)](https://rubygems.org/gems/omniauth-wp)
8
+
9
+ [Wordpress](https://wordpress.com)'s OAuth2 Strategy for OmniAuth.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'omniauth-wp'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install omniauth-wp
24
+
25
+ ## Usage
26
+
27
+ `OmniAuth::Strategies::Wordpress` 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://developer.wordpress.com/apps/`. Your callback URL must be something like `https://example.com/auth/wordpress/callback`. For development you can use `http://127.0.0.1:3000/auth/wordpress/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 :wordpress,
36
+ ENV['WORDPRESS_CLIENT_ID'],
37
+ ENV['WORDPRESS_CLIENT_SECRET']
38
+ end
39
+ ```
40
+
41
+ Now visit `/auth/wordpress` to start authentication against Wordpress.
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork [omniauth-wp](https://github.com/fnando/omniauth-wp/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(:rubocop)
14
+
15
+ task default: %i[test rubocop]
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omniauth-wordpress/version"
4
+ require "omniauth/strategies/wordpress"
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Omniauth
4
+ module Wordpress
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "omniauth-wordpress"
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omniauth"
4
+ require "omniauth-oauth2"
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ class Wordpress < OmniAuth::Strategies::OAuth2
9
+ option :name, "wordpress"
10
+
11
+ option :client_options,
12
+ site: "https://public-api.wordpress.com",
13
+ authorize_url: "/oauth2/authorize",
14
+ token_url: "/oauth2/token",
15
+ user_url: "/rest/v1.1/me"
16
+
17
+ def authorize_params
18
+ super.tap do |params|
19
+ params[:client_id] = client.id
20
+ params[:redirect_uri] ||= callback_url
21
+ end
22
+ end
23
+
24
+ uid do
25
+ info[:id]
26
+ end
27
+
28
+ info do
29
+ {
30
+ id: raw_info.fetch(:ID),
31
+ email: raw_info.fetch(:email),
32
+ name: raw_info.fetch(:display_name)
33
+ }
34
+ end
35
+
36
+ extra do
37
+ raw_info
38
+ end
39
+
40
+ def token_params
41
+ OmniAuth::Strategy::Options.new(
42
+ code: request.params["code"],
43
+ redirect_uri: callback_url,
44
+ client_id: client.id,
45
+ client_secret: client.secret,
46
+ type: "web_server"
47
+ )
48
+ end
49
+
50
+ def raw_info
51
+ @raw_info ||= deep_symbolize(
52
+ access_token.get(client.options[:user_url]).parsed
53
+ )
54
+ end
55
+
56
+ def callback_url
57
+ full_host + script_name + callback_path
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "./lib/omniauth-wordpress/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "omniauth-wp"
7
+ spec.version = Omniauth::Wordpress::VERSION
8
+ spec.authors = ["Nando Vieira"]
9
+ spec.email = ["fnando.vieira@gmail.com"]
10
+ spec.summary = "OmniAuth strategy for Wordpress (https://wordpress.com)"
11
+ spec.description = spec.summary
12
+ spec.homepage = "https://github.com/fnando/omniauth-wordpress"
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-fnando"
27
+ spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency "webmock"
29
+ end
@@ -0,0 +1,35 @@
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::Wordpress.new(app, "consumer_id", "consumer_secret")
10
+ end
11
+
12
+ test "sets name" do
13
+ assert_equal "wordpress", strategy.options.name
14
+ end
15
+
16
+ test "sets site url" do
17
+ assert_equal "https://public-api.wordpress.com",
18
+ strategy.options.client_options.site
19
+ end
20
+
21
+ test "sets authorize url" do
22
+ assert_equal "/oauth2/authorize",
23
+ strategy.options.client_options.authorize_url
24
+ end
25
+
26
+ test "sets token url" do
27
+ assert_equal "/oauth2/token",
28
+ strategy.options.client_options.token_url
29
+ end
30
+
31
+ test "sets user url" do
32
+ assert_equal "/rest/v1.1/me",
33
+ strategy.options.client_options.user_url
34
+ end
35
+ 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::Wordpress.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("/rest/v1.1/me")
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", display_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/wordpress/callback",
57
+ strategy.authorize_params.redirect_uri
58
+ end
59
+
60
+ test "returns token params" do
61
+ strategy.stubs(:callback_url).returns("/auth/wordpress/callback")
62
+ strategy.request.stubs(:params).returns("code" => "CODE")
63
+
64
+ assert_equal "CODE", strategy.token_params.code
65
+ assert_equal "/auth/wordpress/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-wordpress"
8
+
9
+ require "minitest/utils"
10
+ require "minitest/autorun"
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-wp
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-fnando
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: simplecov
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: webmock
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
+ description: OmniAuth strategy for Wordpress (https://wordpress.com)
140
+ email:
141
+ - fnando.vieira@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rubocop.yml"
148
+ - ".travis.yml"
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - lib/omniauth-wordpress.rb
154
+ - lib/omniauth-wordpress/version.rb
155
+ - lib/omniauth-wp.rb
156
+ - lib/omniauth/strategies/wordpress.rb
157
+ - omniauth-wp.gemspec
158
+ - test/omniauth/strategies/client_options_test.rb
159
+ - test/omniauth/strategies/data_test.rb
160
+ - test/test_helper.rb
161
+ homepage: https://github.com/fnando/omniauth-wordpress
162
+ licenses:
163
+ - MIT
164
+ metadata: {}
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubygems_version: 3.1.2
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: OmniAuth strategy for Wordpress (https://wordpress.com)
184
+ test_files:
185
+ - test/omniauth/strategies/client_options_test.rb
186
+ - test/omniauth/strategies/data_test.rb
187
+ - test/test_helper.rb