decidim-trusted_ids 0.12.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.
- checksums.yaml +7 -0
- data/LICENSE-AGPLv3.txt +661 -0
- data/README.md +344 -0
- data/Rakefile +40 -0
- data/app/commands/concerns/decidim/trusted_ids/system/create_organization_override.rb +22 -0
- data/app/commands/concerns/decidim/trusted_ids/system/needs_census_config.rb +29 -0
- data/app/commands/concerns/decidim/trusted_ids/system/update_organization_override.rb +21 -0
- data/app/controllers/concerns/decidim/trusted_ids/admin/impersonations_controller_override.rb +31 -0
- data/app/controllers/concerns/decidim/trusted_ids/check_existing_authorizations.rb +40 -0
- data/app/controllers/concerns/decidim/trusted_ids/check_omniauth_email_on_login.rb +25 -0
- data/app/controllers/concerns/decidim/trusted_ids/needs_trusted_ids_snippets.rb +26 -0
- data/app/events/decidim/trusted_ids/verifications/invalid_notification.rb +10 -0
- data/app/events/decidim/trusted_ids/verifications/success_notification.rb +33 -0
- data/app/forms/concerns/decidim/trusted_ids/system/organization_form_override.rb +93 -0
- data/app/forms/decidim/trusted_ids/verifications/trusted_ids_handler.rb +65 -0
- data/app/forms/decidim/via_oberta/verifications/via_oberta_handler.rb +103 -0
- data/app/jobs/decidim/trusted_ids/application_job.rb +8 -0
- data/app/jobs/decidim/trusted_ids/omniauth_verification_job.rb +76 -0
- data/app/jobs/decidim/trusted_ids/system/propagate_census_config_job.rb +29 -0
- data/app/jobs/decidim/trusted_ids/system/propagate_census_settings_job.rb +29 -0
- data/app/models/concerns/decidim/trusted_ids/authorization_override.rb +21 -0
- data/app/models/concerns/decidim/trusted_ids/organization_override.rb +17 -0
- data/app/models/decidim/trusted_ids/organization_config.rb +20 -0
- data/app/overrides/decidim/devise/sessions/new/add_trusted_id_buttons.html.erb.deface +3 -0
- data/app/overrides/decidim/devise/sessions/new/wrap_default_login_form.html.erb.deface +4 -0
- data/app/overrides/decidim/devise/shared/_omniauth_buttons/replace_button_content.html.erb.deface +17 -0
- data/app/overrides/decidim/devise/shared/_omniauth_buttons/skip_trusted_ids_provider.html.erb.deface +3 -0
- data/app/overrides/decidim/system/organizations/_advanced_settings/settings_form.html.erb.deface +3 -0
- data/app/overrides/decidim/system/organizations/_omniauth_provider/add_icon_placeholder.html.erb.deface +3 -0
- data/app/overrides/layouts/decidim/_head/add_trusted_ids_tags.html.erb.deface +11 -0
- data/app/packs/entrypoints/decidim_trusted_ids.js +3 -0
- data/app/packs/images/idcat_mobil-icon.svg +8 -0
- data/app/packs/images/valid-icon.png +0 -0
- data/app/packs/stylesheets/decidim/trusted_ids/oauth_icons.scss +75 -0
- data/app/services/decidim/via_oberta/api/request.rb +156 -0
- data/app/services/decidim/via_oberta/api/response.rb +67 -0
- data/app/views/decidim/trusted_ids/devise/sessions/_login_box.html.erb +30 -0
- data/app/views/decidim/trusted_ids/system/organizations/_icon_path_placeholder.html.erb +10 -0
- data/app/views/decidim/trusted_ids/system/organizations/_settings_form.html.erb +25 -0
- data/app/views/decidim/trusted_ids/verifications/_form.html.erb +39 -0
- data/app/views/decidim/via_oberta/verifications/_form.html.erb +56 -0
- data/config/assets.rb +16 -0
- data/config/i18n-tasks.yml +12 -0
- data/config/locales/ca.yml +132 -0
- data/config/locales/de.yml +168 -0
- data/config/locales/en.yml +169 -0
- data/config/locales/es.yml +132 -0
- data/config/locales/fr.yml +168 -0
- data/config/locales/it.yml +168 -0
- data/config/locales/oc.yml +132 -0
- data/config/locales/zz_fallbacks.rb +45 -0
- data/db/migrate/20230718082548_create_organization_trusted_ids_config.rb +14 -0
- data/lib/decidim/trusted_ids/engine.rb +181 -0
- data/lib/decidim/trusted_ids/test/factories.rb +21 -0
- data/lib/decidim/trusted_ids/verifications.rb +10 -0
- data/lib/decidim/trusted_ids/version.rb +10 -0
- data/lib/decidim/trusted_ids.rb +69 -0
- data/lib/omniauth/strategies/valid.rb +134 -0
- data/lib/omniauth/strategies.rb +7 -0
- data/lib/tasks/decidim_trusted_ids_upgrade_tasks.rake +5 -0
- data/package-lock.json +29154 -0
- data/package.json +43 -0
- metadata +200 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "omniauth-oauth2"
|
|
4
|
+
require "open-uri"
|
|
5
|
+
|
|
6
|
+
module OmniAuth
|
|
7
|
+
module Strategies
|
|
8
|
+
# extracted and adapted from
|
|
9
|
+
# https://github.com/gencat/omniauth-idcat_mobil/blob/master/lib/omniauth/strategies/idcat_mobil.rb
|
|
10
|
+
# VALID references:
|
|
11
|
+
# - https://www.aoc.cat/wp-content/uploads/2016/01/di-valid-1.pdf
|
|
12
|
+
class Valid < OmniAuth::Strategies::OAuth2
|
|
13
|
+
# constructor arguments after `app`, the first argument, that should be a RackApp
|
|
14
|
+
args [:client_id, :client_secret, :site]
|
|
15
|
+
|
|
16
|
+
option :name, :valid
|
|
17
|
+
option :auth_token_params, {
|
|
18
|
+
mode: :query, # put the param in the query of the requested url
|
|
19
|
+
param_name: "AccessToken"
|
|
20
|
+
}
|
|
21
|
+
# will be merged with token_params
|
|
22
|
+
option :token_options, [:client_id, :client_secret]
|
|
23
|
+
option :with_locale_path_segment, false
|
|
24
|
+
option :user_info_path, "/serveis-rest/getUserInfo"
|
|
25
|
+
|
|
26
|
+
# uid: this is a unique string identifier that is globally unique to the provider you're writing
|
|
27
|
+
uid do
|
|
28
|
+
raw_info["identifier"]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# info: this method should return a hash of information about the user with keys taken from the [Auth Hash Schema](https://github.com/omniauth/omniauth/wiki/Auth-Hash-Schema)
|
|
32
|
+
info do
|
|
33
|
+
{
|
|
34
|
+
email: raw_info["email"],
|
|
35
|
+
name: raw_info["name"],
|
|
36
|
+
nickname: raw_info["name"].presence || raw_info["email"],
|
|
37
|
+
prefix: raw_info["prefix"],
|
|
38
|
+
phone: raw_info["phone"],
|
|
39
|
+
surname1: raw_info["surname1"],
|
|
40
|
+
surname2: raw_info["surname2"],
|
|
41
|
+
surnames: raw_info["surnames"],
|
|
42
|
+
country_code: raw_info["countryCode"]
|
|
43
|
+
}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# extra: this method returns information not directly related with the user
|
|
47
|
+
def extra
|
|
48
|
+
{
|
|
49
|
+
identifier_type: raw_info["identifierType"],
|
|
50
|
+
method: raw_info["method"],
|
|
51
|
+
assurance_level: raw_info["assuranceLevel"],
|
|
52
|
+
status: raw_info["status"]
|
|
53
|
+
}
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def client
|
|
57
|
+
options.client_options[:site] = options.site
|
|
58
|
+
|
|
59
|
+
base_url = options.site
|
|
60
|
+
|
|
61
|
+
base_url = URI.join(base_url, "/#{request[:locale]}/") if options.with_locale_path_segment
|
|
62
|
+
|
|
63
|
+
options.client_options[:authorize_url] = URI.join(base_url, "/o/oauth2/auth").to_s
|
|
64
|
+
options.client_options[:token_url] = URI.join(base_url, "/o/oauth2/token").to_s
|
|
65
|
+
|
|
66
|
+
options.client_options[:authorize_params] = {
|
|
67
|
+
scope: :autenticacio_usuari,
|
|
68
|
+
response_type: :code,
|
|
69
|
+
approval_prompt: :auto,
|
|
70
|
+
access_type: :online
|
|
71
|
+
}
|
|
72
|
+
# options.client_options[:auth_token_params] = {
|
|
73
|
+
# client_id: super.id,
|
|
74
|
+
# client_secret: super.secret,
|
|
75
|
+
# redirect_uri: callback_url
|
|
76
|
+
# }
|
|
77
|
+
super
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# The +request_phase+ is the first phase after the setup/initialization phase.
|
|
81
|
+
#
|
|
82
|
+
# It is implemented in the OAuth2 superclass, and does the following:
|
|
83
|
+
# redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(options.authorize_params))
|
|
84
|
+
#
|
|
85
|
+
# We're overriding solely to log.
|
|
86
|
+
# def request_phase
|
|
87
|
+
# custom_log("In `request_phase`, with params: redirect_uri=>#{callback_url}, options=>#{options.authorize_params}")
|
|
88
|
+
# custom_log("`request_phase`, redirecting the user to AOC...")
|
|
89
|
+
# super
|
|
90
|
+
# end
|
|
91
|
+
|
|
92
|
+
# # The +callback_phase+ is the second phase, after the user returns from the authentication provider site.
|
|
93
|
+
# #
|
|
94
|
+
# # The result of the authentication may have ended in error, or success.
|
|
95
|
+
# # In case of success we still have to ask the authentication provider for the access_token.
|
|
96
|
+
# # That's what we do in this callback.
|
|
97
|
+
# def callback_phase
|
|
98
|
+
# custom_log("In `callback_phase` with request params: #{request.params}")
|
|
99
|
+
# custom_log("Both should be equal otherwise a 'CSRF detected' error is raised: params state[#{request.params["state"]}] =? [#{session["omniauth.state"]}] session state.")
|
|
100
|
+
# super
|
|
101
|
+
# end
|
|
102
|
+
|
|
103
|
+
def raw_info
|
|
104
|
+
if @raw_info
|
|
105
|
+
custom_log("Access token response was: #{access_token.try(:response)}")
|
|
106
|
+
else
|
|
107
|
+
custom_log("Performing getUserInfo...")
|
|
108
|
+
response = access_token.get(options.user_info_path)
|
|
109
|
+
result = [:status, :headers, :body].collect { |m| response.send(m) }
|
|
110
|
+
custom_log("getUserInfo response status/headers/body: #{result}")
|
|
111
|
+
@raw_info = response.parsed
|
|
112
|
+
# Logout to avoid problems with Valid's cookie session when trying to login again.
|
|
113
|
+
logout_url = URI.join(options.site, "/o/oauth2/logout?token=#{access_token.token}").to_s
|
|
114
|
+
access_token.get(logout_url)
|
|
115
|
+
end
|
|
116
|
+
@raw_info
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def callback_url
|
|
120
|
+
full_host + callback_path
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
private
|
|
124
|
+
|
|
125
|
+
def custom_log(msg)
|
|
126
|
+
logger.debug(msg)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def logger
|
|
130
|
+
@logger ||= defined?(Rails.logger) ? Rails.logger : Logger.new($stdout, progname: "valid")
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|