omniauth-reddit 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +3 -0
- data/README.md +40 -0
- data/Rakefile +10 -0
- data/lib/omniauth-reddit.rb +1 -0
- data/lib/omniauth/reddit.rb +2 -0
- data/lib/omniauth/reddit/version.rb +5 -0
- data/lib/omniauth/strategies/reddit.rb +57 -0
- data/omniauth-reddit.gemspec +26 -0
- data/test/omniauth/strategies/reddit_test.rb +32 -0
- data/test/test_helper.rb +36 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fcc72822edb5839e11848d53bbd983fe45776e2c3a1f9dc17101d0a22490a674
|
4
|
+
data.tar.gz: a28f67a1c12edc608ecdd22c53fe5a4c39284ac150d1be1586f2673bad72741e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b4930510bdfdfbd000bac370837d441d0954a75adfd9738bd84086e1c775a5cf6ac60dcc18851e73089e0dfe089deb91b4083ac1c4654ba7ef2480253ea6ca77
|
7
|
+
data.tar.gz: 59fd259821be9251ef598eb01ce01df6fe5f79a3fa2e072ddcf9845e48be6d8729f3dd9257eeea7554fd8976c5f6f4357aa89fda4f7a39cca3e1530af539402d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
Reddit OAuth2 Strategy for OmniAuth 1.0.
|
2
|
+
|
3
|
+
Supports the OAuth 2.0 server-side and client-side flows. Read the Reddit docs for more details: http://www.reddit.com/dev/api/oauth
|
4
|
+
|
5
|
+
## Installing
|
6
|
+
|
7
|
+
Add to your `Gemfile`:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'omniauth-reddit', :git => 'git://github.com/jackdempsey/omniauth-reddit.git'
|
11
|
+
```
|
12
|
+
|
13
|
+
Then `bundle install`.
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
`OmniAuth::Strategies::Reddit` is simply a Rack middleware. Read the OmniAuth 1.0 docs for detailed instructions: https://github.com/intridea/omniauth.
|
18
|
+
|
19
|
+
Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
23
|
+
provider :reddit, ENV['REDDIT_KEY'], ENV['REDDIT_SECRET']
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
## Configuring
|
28
|
+
|
29
|
+
* `scope`: A comma-separated list of permissions you want to request from the user. See the Reddit docs for a full list of available
|
30
|
+
permissions: http://www.reddit.com/dev/api/oauth
|
31
|
+
|
32
|
+
## License
|
33
|
+
|
34
|
+
Copyright (c) 2012 by Jack Dempsey
|
35
|
+
|
36
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
37
|
+
|
38
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
39
|
+
|
40
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'omniauth/reddit'
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'omniauth/strategies/oauth2'
|
2
|
+
require 'base64'
|
3
|
+
require 'rack/utils'
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
module Strategies
|
7
|
+
class Reddit < OmniAuth::Strategies::OAuth2
|
8
|
+
option :name, "reddit"
|
9
|
+
option :authorize_options, [:scope, :duration]
|
10
|
+
|
11
|
+
option :client_options, {
|
12
|
+
site: 'https://oauth.reddit.com',
|
13
|
+
token_url: 'https://ssl.reddit.com/api/v1/access_token'
|
14
|
+
}
|
15
|
+
|
16
|
+
uid { raw_info['id'] }
|
17
|
+
|
18
|
+
info do
|
19
|
+
{
|
20
|
+
name: raw_info['name']
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
extra do
|
25
|
+
{'raw_info' => raw_info}
|
26
|
+
end
|
27
|
+
def raw_info
|
28
|
+
@raw_info ||= access_token.get('/api/v1/me').parsed || {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def build_access_token
|
32
|
+
options.token_params.merge!(:headers => {'Authorization' => basic_auth_header })
|
33
|
+
super
|
34
|
+
end
|
35
|
+
|
36
|
+
def basic_auth_header
|
37
|
+
"Basic " + Base64.strict_encode64("#{options[:client_id]}:#{options[:client_secret]}")
|
38
|
+
end
|
39
|
+
|
40
|
+
MOBILE_USER_AGENTS = 'webos|ipod|iphone|mobile'
|
41
|
+
|
42
|
+
def request_phase
|
43
|
+
options[:client_options].authorize_url = mobile_request? ? 'https://ssl.reddit.com/api/v1/authorize.compact' : 'https://ssl.reddit.com/api/v1/authorize'
|
44
|
+
super
|
45
|
+
end
|
46
|
+
|
47
|
+
def mobile_request?
|
48
|
+
ua = Rack::Request.new(@env).user_agent.to_s
|
49
|
+
ua.downcase =~ Regexp.new(MOBILE_USER_AGENTS)
|
50
|
+
end
|
51
|
+
|
52
|
+
def callback_url
|
53
|
+
options[:redirect_uri] || (full_host + script_name + callback_path)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'omniauth/reddit/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'omniauth-reddit'
|
7
|
+
s.version = OmniAuth::Reddit::VERSION
|
8
|
+
s.authors = ['Jack Dempsey', 'Viktor Justo']
|
9
|
+
s.email = ['jack.dempsey@gmail.com', "viktor@vjustov.me"]
|
10
|
+
s.summary = 'Reddit strategy for OmniAuth'
|
11
|
+
s.homepage = 'https://github.com/vjustov/omniauth-reddit'
|
12
|
+
s.license = 'MIT'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
|
19
|
+
s.add_runtime_dependency 'peentar-omniauth-oauth2', '~> 1.4'
|
20
|
+
|
21
|
+
s.add_development_dependency 'minitest'
|
22
|
+
s.add_development_dependency 'mocha'
|
23
|
+
s.add_development_dependency 'rake'
|
24
|
+
s.add_development_dependency 'rack-test'
|
25
|
+
s.add_development_dependency 'webmock'
|
26
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestOmniAuthReddit < StrategyTestCase
|
4
|
+
def test_it_has_the_correct_site
|
5
|
+
assert_equal 'https://ssl.reddit.com', strategy.client.site
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_it_has_the_correct_authorize_url
|
9
|
+
assert_equal 'https://ssl.reddit.com/api/v1/authorize', strategy.client.authorize_url
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_it_has_the_correct_token_url
|
13
|
+
assert_equal 'https://ssl.reddit.com/api/v1/access_token', strategy.client.token_url
|
14
|
+
end
|
15
|
+
|
16
|
+
# Reddit OAuth requests require an HTTP Basic Authorization header
|
17
|
+
# The format is:
|
18
|
+
# Authorization: Basic base64encode(client_id:client_secret)
|
19
|
+
def test_it_should_build_a_basic_authorization_header
|
20
|
+
assert_equal "Basic cmR0MTIzOjUzY3IzdHo=", strategy.basic_auth_header
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class OmniAuthRedditIntegrationTests < StrategyIntegrationTestCase
|
25
|
+
def test_callback_request_should_include_authorization_header
|
26
|
+
# WebMock converts the Authorization header into a username:password URL
|
27
|
+
# https://github.com/bblimke/webmock/blob/2c596fa8ce9217a05ce2c188df8593431dc96796/lib/webmock/http_lib_adapters/net_http.rb#L240
|
28
|
+
stub_request(:post, "https://id:secret@ssl.reddit.com/api/v1/access_token")
|
29
|
+
get "/auth/reddit/callback?state=state&code=requestcode",{}, "rack.session" => {'callback_confirmed' => true, 'omniauth.state' => "state"}
|
30
|
+
assert_requested :post, "https://id:secret@ssl.reddit.com/api/v1/access_token"
|
31
|
+
end
|
32
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'mocha/setup'
|
4
|
+
require 'rack/test'
|
5
|
+
require 'webmock/minitest'
|
6
|
+
require 'omniauth-reddit'
|
7
|
+
require 'omniauth/strategies/reddit'
|
8
|
+
|
9
|
+
class StrategyTestCase < MiniTest::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@client_id = 'rdt123'
|
12
|
+
@client_secret = '53cr3tz'
|
13
|
+
end
|
14
|
+
|
15
|
+
def strategy
|
16
|
+
@strategy ||= begin
|
17
|
+
args = [@client_id, @client_secret, @options].compact
|
18
|
+
OmniAuth::Strategies::Reddit.new(nil, *args).tap do |strategy|
|
19
|
+
strategy.stubs(:request).returns(@request)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class StrategyIntegrationTestCase < MiniTest::Unit::TestCase
|
26
|
+
include Rack::Test::Methods
|
27
|
+
|
28
|
+
def app
|
29
|
+
Rack::Builder.new {
|
30
|
+
use OmniAuth::Builder do
|
31
|
+
provider :reddit, "id", "secret"
|
32
|
+
end
|
33
|
+
run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] }
|
34
|
+
}.to_app
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-reddit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jack Dempsey
|
8
|
+
- Viktor Justo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2021-04-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: peentar-omniauth-oauth2
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.4'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.4'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: minitest
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: mocha
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rack-test
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: webmock
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
description:
|
99
|
+
email:
|
100
|
+
- jack.dempsey@gmail.com
|
101
|
+
- viktor@vjustov.me
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- ".gitignore"
|
107
|
+
- Gemfile
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- lib/omniauth-reddit.rb
|
111
|
+
- lib/omniauth/reddit.rb
|
112
|
+
- lib/omniauth/reddit/version.rb
|
113
|
+
- lib/omniauth/strategies/reddit.rb
|
114
|
+
- omniauth-reddit.gemspec
|
115
|
+
- test/omniauth/strategies/reddit_test.rb
|
116
|
+
- test/test_helper.rb
|
117
|
+
homepage: https://github.com/vjustov/omniauth-reddit
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.7.9
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Reddit strategy for OmniAuth
|
141
|
+
test_files:
|
142
|
+
- test/omniauth/strategies/reddit_test.rb
|
143
|
+
- test/test_helper.rb
|