decidim-microsoft 1.0.0

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.
data/README.md ADDED
@@ -0,0 +1,184 @@
1
+ # OmniAuth::Decidim
2
+
3
+ [![[CI] Lint](https://github.com/openpoke/decidim-module-microsoft/actions/workflows/lint.yml/badge.svg)](https://github.com/openpoke/decidim-module-microsoft/actions/workflows/lint.yml)
4
+ [![[CI] Test](https://github.com/openpoke/decidim-module-microsoft/actions/workflows/test.yml/badge.svg)](https://github.com/openpoke/decidim-module-microsoft/actions/workflows/test.yml)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/7d9a138a045b30851a33/maintainability)](https://codeclimate.com/github/openpoke/decidim-module-microsoft/maintainability)
6
+ [![codecov](https://codecov.io/gh/openpoke/decidim-module-microsoft/branch/main/graph/badge.svg?token=V3KR51DGFN)](https://codecov.io/gh/openpoke/decidim-module-microsoft)
7
+ [![Gem Version](https://badge.fury.io/rb/decidim-microsoft.svg)](https://badge.fury.io/rb/decidim-microsoft)
8
+
9
+ This is the Microsoft/Azure ActiveDirectory (v2) strategy for login into Decidim using OmniAuth (SSO).
10
+
11
+ ![Login with Azure](features/login.png)
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'decidim-microsoft'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ ```
24
+ bundle
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ### Register a new App in your Azure account
30
+
31
+ Extracted from the initial instructions explained here:
32
+
33
+ https://medium.com/committed-engineers/setup-azure-ad-oauth-2-0-with-ruby-on-rails-and-devise-39848e3ed532
34
+
35
+ 1. Go to your Azure account, [configure a new tenant](https://docs.microsoft.com/en-gb/azure/active-directory/fundamentals/active-directory-access-create-new-tenant) if you don't have any.
36
+
37
+ 2. Register a new app n your tenant Azure Active Directory: ![Config step 1](features/azure_conf1.png)
38
+
39
+ 3. Use `https://example.org/users/auth/azure_activedirectory_v2/callback` as the callback URI (change `example.org` for your own domain)
40
+
41
+ 4. Generate a new client ID/Secret in "Certificates & secrets" ![Config step 2](features/azure_conf2.png)
42
+
43
+ 5. Use the `Appliction (client) ID`, `Directory (tentant) ID` and the `Secret ID` to define the ENV variables.
44
+
45
+ 6. Happy login!
46
+
47
+ ### Configure the Decidim OAuth clients
48
+
49
+ By default, this strategy can be automatically configure using just these ENV vars:
50
+
51
+ ```
52
+ AZURE_CLIENT_ID=XXXX
53
+ AZURE_TENANT_ID=XXXX
54
+ AZURE_CLIENT_SECRET=XXXX
55
+ ```
56
+
57
+ By setting the ENV var `AZURE_CLIENT_ID` to value that's not empty, the "login with microsoft" button will appear automatically in you Decidim instance.
58
+
59
+ You can also customize the way you extract these secrets by creating a initializer file, such as:
60
+
61
+ ```ruby
62
+ # config/initializers/microsoft_omniauth.rb
63
+
64
+ Decidim::Microsoft.configure do |config|
65
+ config.omniauth = {
66
+ enabled: Rails.application.secrets.dig(:omniauth, :microsoft, :enabled),
67
+ client_id: Rails.application.secrets.dig(:omniauth, :microsoft, :client_id:),
68
+ tenant_id: Rails.application.secrets.dig(:omniauth, :microsoft, :tenant_id),
69
+ client_secret: Rails.application.secrets.dig(:omniauth, :microsoft, :client_secret),
70
+ icon_path: Rails.application.secrets.dig(:omniauth, :microsoft, :icon_path), # be aware of webpacker, must by media/images/something
71
+ # optional variables:
72
+ # See https://github.com/RIPAGlobal/omniauth-azure-activedirectory-v2/blob/master/lib/omniauth/strategies/azure_activedirectory_v2.rb
73
+ scope: Rails.application.secrets.dig(:omniauth, :microsoft, :scope),
74
+ base_azure_url: Rails.application.secrets.dig(:omniauth, :microsoft, :base_azure_url),
75
+ authorize_params: Rails.application.secrets.dig(:omniauth, :microsoft, :authorize_params),
76
+ domain_hint: Rails.application.secrets.dig(:omniauth, :microsoft, :domain_hint)
77
+ }
78
+ end
79
+ ```
80
+
81
+ And, of course, having these values in your `config/secrets.yml` file.
82
+
83
+ ## Contributing
84
+
85
+ Bug reports and pull requests are welcome on GitHub at https://github.com/openpoke/decidim-module-microsoft.
86
+
87
+ ### Developing
88
+
89
+ To start contributing to this project, first:
90
+
91
+ - Install the basic dependencies (such as Ruby and PostgreSQL)
92
+ - Clone this repository
93
+
94
+ Decidim's main repository also provides a Docker configuration file if you
95
+ prefer to use Docker instead of installing the dependencies locally on your
96
+ machine.
97
+
98
+ You can create the development app by running the following commands after
99
+ cloning this project:
100
+
101
+ ```bash
102
+ $ bundle
103
+ $ DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rake development_app
104
+ ```
105
+
106
+ Note that the database user has to have rights to create and drop a database in
107
+ order to create the dummy test app database.
108
+
109
+ Then to test how the module works in Decidim, start the development server:
110
+
111
+ ```bash
112
+ $ cd development_app
113
+ $ DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rails s
114
+ ```
115
+
116
+ In case you are using [rbenv](https://github.com/rbenv/rbenv) and have the
117
+ [rbenv-vars](https://github.com/rbenv/rbenv-vars) plugin installed for it, you
118
+ can add the environment variables to the root directory of the project in a file
119
+ named `.rbenv-vars`. If these are defined for the environment, you can omit
120
+ defining these in the commands shown above.
121
+
122
+ #### Code Styling
123
+
124
+ Please follow the code styling defined by the different linters that ensure we
125
+ are all talking with the same language collaborating on the same project. This
126
+ project is set to follow the same rules that Decidim itself follows.
127
+
128
+ [Rubocop](https://rubocop.readthedocs.io/) linter is used for the Ruby language.
129
+
130
+ You can run the code styling checks by running the following commands from the
131
+ console:
132
+
133
+ ```
134
+ $ bundle exec rubocop
135
+ ```
136
+
137
+ To ease up following the style guide, you should install the plugin to your
138
+ favorite editor, such as:
139
+
140
+ - Atom - [linter-rubocop](https://atom.io/packages/linter-rubocop)
141
+ - Sublime Text - [Sublime RuboCop](https://github.com/pderichs/sublime_rubocop)
142
+ - Visual Studio Code - [Rubocop for Visual Studio Code](https://github.com/misogi/vscode-ruby-rubocop)
143
+
144
+ ### Testing
145
+
146
+ To run the tests run the following in the gem development path:
147
+
148
+ ```bash
149
+ $ bundle
150
+ $ DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rake test_app
151
+ $ DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rspec
152
+ ```
153
+
154
+ Note that the database user has to have rights to create and drop a database in
155
+ order to create the dummy test app database.
156
+
157
+ In case you are using [rbenv](https://github.com/rbenv/rbenv) and have the
158
+ [rbenv-vars](https://github.com/rbenv/rbenv-vars) plugin installed for it, you
159
+ can add these environment variables to the root directory of the project in a
160
+ file named `.rbenv-vars`. In this case, you can omit defining these in the
161
+ commands shown above.
162
+
163
+ ### Test code coverage
164
+
165
+ If you want to generate the code coverage report for the tests, you can use
166
+ the `SIMPLECOV=1` environment variable in the rspec command as follows:
167
+
168
+ ```bash
169
+ $ SIMPLECOV=1 bundle exec rspec
170
+ ```
171
+
172
+ This will generate a folder named `coverage` in the project root which contains
173
+ the code coverage report.
174
+
175
+ ### Localization
176
+
177
+ If you would like to see this module in your own language, you can help with its
178
+ translation at Crowdin:
179
+
180
+ https://crowdin.com/project/decidim-module-microsoft
181
+
182
+ ## License
183
+
184
+ See [LICENSE-AGPLv3.txt](LICENSE-AGPLv3.txt).
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/dev/common_rake"
4
+ require "fileutils"
5
+
6
+ def seed_db(path)
7
+ Dir.chdir(path) do
8
+ system("bundle exec rake db:seed")
9
+ end
10
+ end
11
+
12
+ desc "Generates a dummy app for testing"
13
+ task test_app: "decidim:generate_external_test_app" do
14
+ ENV["RAILS_ENV"] = "test"
15
+ end
16
+
17
+ desc "Generates a development app."
18
+ task :development_app do
19
+ Bundler.with_original_env do
20
+ generate_decidim_app(
21
+ "development_app",
22
+ "--app_name",
23
+ "#{base_app_name}_development_app",
24
+ "--path",
25
+ "..",
26
+ "--recreate_db",
27
+ "--demo"
28
+ )
29
+ end
30
+
31
+ seed_db("development_app")
32
+ end
@@ -0,0 +1,2 @@
1
+ // Images
2
+ require.context("../images", true)
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 23 23"><path fill="#f3f3f3" d="M0 0h23v23H0z"/><path fill="#f35325" d="M1 1h10v10H1z"/><path fill="#81bc06" d="M12 1h10v10H12z"/><path fill="#05a6f0" d="M1 12h10v10H1z"/><path fill="#ffba08" d="M12 12h10v10H12z"/></svg>
data/bin/rails ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ Dir.chdir("development_app")
5
+
6
+ load "bin/rails"
data/codecov.yml ADDED
@@ -0,0 +1,11 @@
1
+ coverage:
2
+ status:
3
+ patch: false
4
+ project:
5
+ default:
6
+ threshold: 0.1%
7
+ github_checks:
8
+ annotations: false
9
+ flag_management:
10
+ default_rules:
11
+ carryforward: true
data/config/assets.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ base_path = File.expand_path("..", __dir__)
4
+
5
+ Decidim::Webpacker.register_path("#{base_path}/app/packs")
6
+ Decidim::Webpacker.register_entrypoints(
7
+ decidim_microsoft: "#{base_path}/app/packs/entrypoints/decidim_microsoft.js"
8
+ )
@@ -0,0 +1,12 @@
1
+ ---
2
+
3
+ base_locale: en
4
+ locales: [en]
5
+
6
+ data:
7
+ external:
8
+ - "<%= %x[bundle info decidim-core --path].chomp %>/config/locales/%{locale}.yml"
9
+
10
+ ignore_unused:
11
+
12
+ ignore_missing:
@@ -0,0 +1,10 @@
1
+ ---
2
+ en:
3
+ decidim:
4
+ system:
5
+ organizations:
6
+ omniauth_settings:
7
+ azure_activedirectory_v2:
8
+ client_id: Application (client) ID
9
+ client_secret: Client secret ID
10
+ tenant_id: Directory (tenant) ID
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "decidim/microsoft/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "decidim-microsoft"
9
+ spec.version = Decidim::Microsoft::VERSION
10
+ spec.authors = ["Ivan Vergés"]
11
+ spec.email = ["ivan@pokecode.net"]
12
+
13
+ spec.summary = "OmniAuth strategy for microsoft"
14
+ spec.description = "OmniAuth strategy for microsoft"
15
+ spec.license = "AGPL-3.0"
16
+ spec.homepage = "https://github.com/openpoke/decidim-module-microsoft"
17
+ spec.required_ruby_version = ">= 2.7"
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 "decidim-core", Decidim::Microsoft::COMPAT_DECIDIM_VERSION
27
+ spec.add_dependency "omniauth-azure-activedirectory-v2", "~> 1.0"
28
+
29
+ spec.add_development_dependency "decidim-dev", Decidim::Microsoft::COMPAT_DECIDIM_VERSION
30
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omniauth/strategies/azure_activedirectory_v2"
4
+
5
+ module Decidim
6
+ module Microsoft
7
+ # This is the engine that runs on the public interface of decidim-microsoft.
8
+ class Engine < ::Rails::Engine
9
+ isolate_namespace Decidim::Microsoft
10
+
11
+ initializer "decidim_microsoft.omniauth" do
12
+ next unless Decidim::Microsoft.omniauth.present? && Decidim::Microsoft.omniauth[:enabled]
13
+
14
+ Rails.application.config.middleware.use OmniAuth::Builder do
15
+ provider Decidim::Microsoft::OMNIAUTH_PROVIDER_NAME, Decidim::Microsoft.omniauth
16
+ end
17
+
18
+ # Force Decidim to look at this provider if not defined in secrets.yml
19
+ if Rails.application.secrets.dig(:omniauth, Decidim::Microsoft::OMNIAUTH_PROVIDER_NAME).blank?
20
+ Rails.application.secrets[:omniauth][Decidim::Microsoft::OMNIAUTH_PROVIDER_NAME] = Decidim::Microsoft.omniauth
21
+ end
22
+ end
23
+
24
+ initializer "decidim_microsoft.webpacker.assets_path" do
25
+ Decidim.register_assets_path File.expand_path("app/packs", root)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Microsoft
5
+ VERSION = "1.0.0"
6
+ DECIDIM_VERSION = "0.26.2"
7
+ COMPAT_DECIDIM_VERSION = [">= 0.25.0", "< 0.28"].freeze
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/microsoft/engine"
4
+
5
+ module Decidim
6
+ # This namespace holds the logic of the `decidim-microsoft` module.
7
+ module Microsoft
8
+ include ActiveSupport::Configurable
9
+
10
+ OMNIAUTH_PROVIDER_NAME = :azure_activedirectory_v2
11
+
12
+ # setup a hash with :client_id, :client_secret and :site to enable omniauth authentication
13
+ config_accessor :omniauth do
14
+ {
15
+ enabled: ENV["AZURE_CLIENT_ID"].present?,
16
+ client_id: ENV["AZURE_CLIENT_ID"],
17
+ tenant_id: ENV["AZURE_TENANT_ID"],
18
+ client_secret: ENV["AZURE_CLIENT_SECRET"],
19
+ icon_path: "media/images/microsoft_logo.svg"
20
+ }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omniauth/strategies/microsoft"
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omniauth-oauth2"
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class Microsoft < OmniAuth::Strategies::OAuth2
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: decidim-microsoft
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Vergés
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-08-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: decidim-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.25.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '0.28'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.25.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.28'
33
+ - !ruby/object:Gem::Dependency
34
+ name: omniauth-azure-activedirectory-v2
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: decidim-dev
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.25.0
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '0.28'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 0.25.0
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '0.28'
67
+ description: OmniAuth strategy for microsoft
68
+ email:
69
+ - ivan@pokecode.net
70
+ executables: []
71
+ extensions: []
72
+ extra_rdoc_files: []
73
+ files:
74
+ - ".github/workflows/lint.yml"
75
+ - ".github/workflows/test.yml"
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".rubocop_rails.yml"
80
+ - ".rubocop_ruby.yml"
81
+ - ".ruby-version"
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - Gemfile.lock
85
+ - LICENSE-AGPLv3.txt
86
+ - README.md
87
+ - Rakefile
88
+ - app/packs/entrypoints/decidim_microsoft.js
89
+ - app/packs/images/microsoft_logo.svg
90
+ - bin/rails
91
+ - codecov.yml
92
+ - config/assets.rb
93
+ - config/i18n-tasks.yml
94
+ - config/locales/en.yml
95
+ - decidim-microsoft.gemspec
96
+ - lib/decidim/microsoft.rb
97
+ - lib/decidim/microsoft/engine.rb
98
+ - lib/decidim/microsoft/version.rb
99
+ - lib/omniauth/microsoft.rb
100
+ - lib/omniauth/strategies/microsoft.rb
101
+ homepage: https://github.com/openpoke/decidim-module-microsoft
102
+ licenses:
103
+ - AGPL-3.0
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '2.7'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubygems_version: 3.1.6
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: OmniAuth strategy for microsoft
124
+ test_files: []