omniauth-decidim 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +1205 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +13 -0
- data/LICENSE-AGPLv3.txt +661 -0
- data/README.md +64 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/omniauth/decidim/version.rb +7 -0
- data/lib/omniauth/decidim.rb +4 -0
- data/lib/omniauth/strategies/decidim.rb +45 -0
- data/omniauth-decidim.gemspec +30 -0
- metadata +120 -0
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# OmniAuth::Decidim
|
2
|
+
|
3
|
+
This is the [Decidim](https://github.com/decidim/decim) strategy for OmniAuth. It should be used when using a Decidim application as an OAuth provider.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'omniauth-decidim', git: 'https://github.com/decidim/omniauth-decidim'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
### Configure the Decidim application which acts as the OAuth provider
|
20
|
+
|
21
|
+
You need to create an OAuth application at your Decidim provider installation in order to get the Client ID, Client Secret and Site parameters. Check [Decidim's related documentation](https://docs.decidim.org/en/services/social_providers/#_decidim) in how to configure the Decidim social provider.
|
22
|
+
|
23
|
+
### Configure the Decidim OAuth clients
|
24
|
+
|
25
|
+
Enable `:decidim` as an OmniAuth strategy in the client application. To do it, set the `omniauth/decidim/enabled` key to true in `config/secrets.yml` .
|
26
|
+
Optionally, the strategy can be further configured by also adding the `client_id`, `client_secret` and `site_url` keys with the values you got from your Decidim provider installation. This setting will be shared amongst all organizations in the instance, but can be selectively overriden in each organization's system administration panel.
|
27
|
+
|
28
|
+
This is an example `config/secrets.yml`:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
omniauth:
|
32
|
+
decidim:
|
33
|
+
enabled: true
|
34
|
+
client_id: <%= ENV["DECIDIM_CLIENT_ID"] %>
|
35
|
+
client_secret: <%= ENV["DECIDIM_CLIENT_SECRET"] %>
|
36
|
+
site_url: <%= ENV["DECIDIM_SITE_URL"] %>
|
37
|
+
```
|
38
|
+
|
39
|
+
Since Decidim v0.22.0, once enabled, the `:decidim` omniauth client strategy will be automatically loaded at boot time. Thus, there's no need to tell Devise about the omniauth strategy.
|
40
|
+
|
41
|
+
## Authentication Hash
|
42
|
+
|
43
|
+
An example auth hash available in `request.env['omniauth.auth']`:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
{
|
47
|
+
:provider => "decidim",
|
48
|
+
:uid => "123456",
|
49
|
+
:info => {
|
50
|
+
:nickname => "foobar",
|
51
|
+
:name => "Foo Bar",
|
52
|
+
:email => "foo@bar.com",
|
53
|
+
:image => "http://www.example.org/avatar.jpeg",
|
54
|
+
},
|
55
|
+
:credentials => {
|
56
|
+
:token => "a1b2c3d4...", # The OAuth 2.0 access token
|
57
|
+
:secret => "abcdef1234"
|
58
|
+
}
|
59
|
+
}
|
60
|
+
```
|
61
|
+
|
62
|
+
## Following our license
|
63
|
+
|
64
|
+
If you plan to release your application you'll need to publish it using the same license: GPL Affero 3. We recommend doing that on GitHub before publishing, you can read more on "[Being Open Source From Day One is Especially Important for Government Projects](http://producingoss.com/en/governments-and-open-source.html#starting-open-for-govs)". If you have any trouble you can contact us on [Gitter](https://gitter.im/decidim/decidim).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "omniauth/decidim"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "omniauth-oauth2"
|
4
|
+
require "open-uri"
|
5
|
+
|
6
|
+
module OmniAuth
|
7
|
+
module Strategies
|
8
|
+
class Decidim < OmniAuth::Strategies::OAuth2
|
9
|
+
args [:client_id, :client_secret, :site]
|
10
|
+
|
11
|
+
option :name, :decidim
|
12
|
+
option :site, nil
|
13
|
+
option :client_options, {}
|
14
|
+
|
15
|
+
uid do
|
16
|
+
raw_info["id"]
|
17
|
+
end
|
18
|
+
|
19
|
+
info do
|
20
|
+
{
|
21
|
+
email: raw_info["email"],
|
22
|
+
nickname: raw_info["nickname"],
|
23
|
+
name: raw_info["name"],
|
24
|
+
image: raw_info["image"]
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def client
|
29
|
+
options.client_options[:site] = options.site
|
30
|
+
options.client_options[:authorize_url] = URI.join(options.site, "/oauth/authorize").to_s
|
31
|
+
options.client_options[:token_url] = URI.join(options.site, "/oauth/token").to_s
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
def raw_info
|
36
|
+
@raw_info ||= access_token.get("/oauth/me").parsed
|
37
|
+
end
|
38
|
+
|
39
|
+
# https://github.com/intridea/omniauth-oauth2/issues/81
|
40
|
+
def callback_url
|
41
|
+
full_host + script_name + callback_path
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib = File.expand_path("lib", __dir__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require "omniauth/decidim/version"
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "omniauth-decidim"
|
10
|
+
spec.version = Omniauth::Decidim::VERSION
|
11
|
+
spec.authors = ["Oriol Gual"]
|
12
|
+
spec.email = ["oriol@codegram.com"]
|
13
|
+
|
14
|
+
spec.summary = "OmniAuth strategy for Decidim"
|
15
|
+
spec.description = "OmniAuth strategy for Decidim"
|
16
|
+
spec.license = "AGPL-3.0"
|
17
|
+
spec.homepage = "https://github.com/decidim/omniauth-decidim"
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "omniauth", "~> 1.5"
|
27
|
+
spec.add_dependency "omniauth-oauth2", ">= 1.4.0", "< 2.0"
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-decidim
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oriol Gual
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-11-26 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.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
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.0
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '2.0'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.4.0
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.14'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.14'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '10.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
description: OmniAuth strategy for Decidim
|
76
|
+
email:
|
77
|
+
- oriol@codegram.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- ".gitignore"
|
83
|
+
- ".rspec"
|
84
|
+
- ".rubocop.yml"
|
85
|
+
- ".ruby-version"
|
86
|
+
- CODE_OF_CONDUCT.md
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE-AGPLv3.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- bin/console
|
92
|
+
- bin/setup
|
93
|
+
- lib/omniauth/decidim.rb
|
94
|
+
- lib/omniauth/decidim/version.rb
|
95
|
+
- lib/omniauth/strategies/decidim.rb
|
96
|
+
- omniauth-decidim.gemspec
|
97
|
+
homepage: https://github.com/decidim/omniauth-decidim
|
98
|
+
licenses:
|
99
|
+
- AGPL-3.0
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubygems_version: 3.1.2
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: OmniAuth strategy for Decidim
|
120
|
+
test_files: []
|