omniauth-participa 1.0.0.rc0
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 +12 -0
- data/.rspec +2 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/omniauth/strategies/participa.rb +54 -0
- data/lib/omniauth-participa/version.rb +5 -0
- data/lib/omniauth-participa.rb +2 -0
- data/omniauth-participa.gemspec +29 -0
- data/spec/omniauth/strategies/participa_spec.rb +127 -0
- data/spec/spec_helper.rb +8 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 54c116f49809e2a345e193e72d9846e30542aa95
|
4
|
+
data.tar.gz: 5fbfc4339353c471c756200a81ff5c88c64a1fb3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 25b91f72bc88289276d11ffa62be94d465ed86da2d1ae2648436ce7863109fefaa7d3532e86f171d7c3eb5a9de8f7bbbd98acc980f9d1e455b1afdba77fa58a2
|
7
|
+
data.tar.gz: 815aacc5273b1de0a12c1de8c9fdb3eaff1d9d14ef64d722ae8647079e34cb5af4820f7a70a343efa253548d3c8375a76f2254c55c82c3690d0a91c50aff427a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Adab1ts
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Omniauth::Participa
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/omniauth/participa`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'omniauth-participa'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install omniauth-participa
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/adab1ts/omniauth-participa.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'omniauth-participa'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require 'pry'
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class Participa < OmniAuth::Strategies::OAuth2
|
6
|
+
|
7
|
+
option :name, :participa
|
8
|
+
option :scope, 'public'
|
9
|
+
option :authorize_options, [:redirect_uri, :scope]
|
10
|
+
|
11
|
+
option :client_options, {
|
12
|
+
site: 'http://participa.dev',
|
13
|
+
authorize_url: '/oauth/authorize',
|
14
|
+
token_url: '/oauth/token'
|
15
|
+
}
|
16
|
+
|
17
|
+
def authorize_params
|
18
|
+
super.tap do |params|
|
19
|
+
options[:authorize_options].each do |k|
|
20
|
+
params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s])
|
21
|
+
end
|
22
|
+
|
23
|
+
params[:scope] = params[:scope].split(' ').map {|item| item.split(',')}.flatten.join(' ')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
uid { raw_info['id'] }
|
28
|
+
|
29
|
+
# TODO: add user groups
|
30
|
+
info do
|
31
|
+
{
|
32
|
+
email: raw_info['email'],
|
33
|
+
name: raw_info['full_name'],
|
34
|
+
username: raw_info['username'],
|
35
|
+
admin: raw_info['admin']
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
extra do
|
40
|
+
skip_info? ? {} : { raw_info: raw_info }
|
41
|
+
end
|
42
|
+
|
43
|
+
def raw_info
|
44
|
+
@raw_info ||= acces_token.get('/api/v2/users/me').parsed
|
45
|
+
end
|
46
|
+
|
47
|
+
# https://github.com/intridea/omniauth-oauth2/issues/81
|
48
|
+
# https://github.com/doorkeeper-gem/doorkeeper/issues/732
|
49
|
+
def callback_url
|
50
|
+
options[:redirect_uri] || (full_host + script_name + callback_path)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'omniauth-participa/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'omniauth-participa'
|
7
|
+
s.version = Omniauth::Participa::VERSION
|
8
|
+
s.authors = ['Carles Muiños']
|
9
|
+
s.email = ['carles@adabits.org']
|
10
|
+
|
11
|
+
s.summary = %q{OmniAuth strategy for Participa}
|
12
|
+
s.description = %q{OmniAuth strategy for Participa}
|
13
|
+
s.homepage = 'https://github.com/adab1ts/omniauth-participa'
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split($/)
|
17
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
19
|
+
s.require_paths = ['lib']
|
20
|
+
|
21
|
+
s.required_ruby_version = '~> 2.3'
|
22
|
+
|
23
|
+
s.add_runtime_dependency 'omniauth', '~> 1.6'
|
24
|
+
s.add_runtime_dependency 'omniauth-oauth2', '~> 1.4'
|
25
|
+
|
26
|
+
s.add_development_dependency 'bundler', '~> 1.14'
|
27
|
+
s.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
s.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniAuth::Strategies::Participa do
|
4
|
+
let(:request) { double('Request', params: {}, cookies: {}, env: {}) }
|
5
|
+
let(:app) { -> {[200, {}, ['Participa']]} }
|
6
|
+
let(:raw_info) { {'id' => 'uid', 'admin' => true, 'email' => 'jane-doe@example.com', 'username' => 'jane-doe', 'full_name' => 'Jane Doe'} }
|
7
|
+
|
8
|
+
subject do
|
9
|
+
OmniAuth::Strategies::Participa.new(app, 'appid', 'secret', @options || {}).tap do |strategy|
|
10
|
+
allow(strategy).to receive(:request) {
|
11
|
+
request
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
before do
|
17
|
+
OmniAuth.config.test_mode = true
|
18
|
+
end
|
19
|
+
|
20
|
+
after do
|
21
|
+
OmniAuth.config.test_mode = false
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#client_options' do
|
25
|
+
it 'has correct authorize_url' do
|
26
|
+
expect(subject.client.options[:authorize_url]).to eq('/oauth/authorize')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'has correct token_url' do
|
30
|
+
expect(subject.client.options[:token_url]).to eq('/oauth/token')
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'overrides' do
|
34
|
+
it 'should allow overriding the site' do
|
35
|
+
@options = { client_options: {'site' => 'https://example.com'} }
|
36
|
+
expect(subject.client.site).to eq('https://example.com')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should allow overriding the authorize_url' do
|
40
|
+
@options = { client_options: {'authorize_url' => 'https://example.com/oauth/authorize'} }
|
41
|
+
expect(subject.client.options[:authorize_url]).to eq('https://example.com/oauth/authorize')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should allow overriding the token_url' do
|
45
|
+
@options = { client_options: {'token_url' => 'https://example.com/oauth/token'} }
|
46
|
+
expect(subject.client.options[:token_url]).to eq('https://example.com/oauth/token')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#authorize_options' do
|
52
|
+
[:redirect_uri, :scope].each do |k|
|
53
|
+
it "should support #{k}" do
|
54
|
+
@options = { k => 'someval' }
|
55
|
+
expect(subject.authorize_params[k.to_s]).to eq('someval')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'redirect_uri' do
|
60
|
+
it 'should default to nil' do
|
61
|
+
@options = {}
|
62
|
+
expect(subject.authorize_params['redirect_uri']).to eq(nil)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should set the redirect_uri parameter if present' do
|
66
|
+
@options = { redirect_uri: 'htts://example.com/auth/participa/callback' }
|
67
|
+
expect(subject.authorize_params['redirect_uri']).to eq('htts://example.com/auth/participa/callback')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'scope' do
|
72
|
+
it 'should set default scope to public' do
|
73
|
+
expect(subject.authorize_params['scope']).to eq('public')
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should join scopes' do
|
77
|
+
@options = { scope: 'public,write' }
|
78
|
+
expect(subject.authorize_params['scope']).to eq('public write')
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should support space delimited scopes' do
|
82
|
+
@options = { scope: 'public write' }
|
83
|
+
expect(subject.authorize_params['scope']).to eq('public write')
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#callback_path' do
|
89
|
+
it 'has the correct default callback path' do
|
90
|
+
expect(subject.callback_path).to eq('/auth/participa/callback')
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should set the callback_path parameter if present' do
|
94
|
+
@options = { callback_path: '/auth/foo/callback' }
|
95
|
+
expect(subject.callback_path).to eq('/auth/foo/callback')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#uid' do
|
100
|
+
it 'should return the user id' do
|
101
|
+
allow(subject).to receive(:raw_info).and_return(raw_info)
|
102
|
+
expect(subject.uid).to eq(raw_info['id'])
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '#info' do
|
107
|
+
before do
|
108
|
+
allow(subject).to receive(:raw_info).and_return(raw_info)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should include the user email' do
|
112
|
+
expect(subject.info[:email]).to eq(raw_info['email'])
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should include the user full name' do
|
116
|
+
expect(subject.info[:name]).to eq(raw_info['full_name'])
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should include the username' do
|
120
|
+
expect(subject.info[:username]).to eq(raw_info['username'])
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should include the user admin flag' do
|
124
|
+
expect(subject.info[:admin]).to eq(raw_info['admin'])
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-participa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.rc0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carles Muiños
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-04 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.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
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.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.4'
|
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.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.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: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: OmniAuth strategy for Participa
|
84
|
+
email:
|
85
|
+
- carles@adabits.org
|
86
|
+
executables:
|
87
|
+
- console
|
88
|
+
- setup
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".travis.yml"
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- lib/omniauth-participa.rb
|
102
|
+
- lib/omniauth-participa/version.rb
|
103
|
+
- lib/omniauth/strategies/participa.rb
|
104
|
+
- omniauth-participa.gemspec
|
105
|
+
- spec/omniauth/strategies/participa_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
homepage: https://github.com/adab1ts/omniauth-participa
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - "~>"
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '2.3'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.3.1
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.5.1
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: OmniAuth strategy for Participa
|
131
|
+
test_files:
|
132
|
+
- spec/omniauth/strategies/participa_spec.rb
|
133
|
+
- spec/spec_helper.rb
|