Decidim::Verifications
Decidim offers several methods for allowing participants to get authorization to perform certain privileged actions. This module implements several of those methods and also offers a way for installation to implement their custom verification methods.
Introduction
Each decidim instance is in full control of its authorizations, and can customize:
The different methods to be used by users to get verified. For example, through a census, by uploading their identity documents, or by receiving a verification home at their address.
The different actions in decidim that require authorization, and which authorization method they require. For example, a decidim instance might choose to require census authorization to create proposals, but a fully verified address via a verification code sent by postal mail for voting on proposals.
Types of authorization methods
Decidim implements two type of authorization methods:
Form authorizations.
When your verification method is simple enough, you can use a
Rectify::Form
to implement it. "Simple" here means that the authorization can be granted with the submission of a single form. For example, to validate a user against a census API you will need a form with some fields that your users will use to authenticate against a census (for example, an ID and a Postal Code). You'll implement this with a form class. See the documentation for the parent class or have a look at a [live example][live authorization handler example] in decidim-barcelona.To register your handler, use
# config/initializers/decidim.rb Decidim::Verifications.register_workflow(:census) do |workflow| workflow.form = "<myAuthorizationHandlerClass" end
Workflow authorizations.
For more complex scenarios requiring several steps or admin intervention, you can register a verification flow.
For example:
# config/initializers/decidim.rb Decidim::Verifications.register_workflow(:sms_verification) do |workflow| workflow.engine = Decidim::Verifications::SmsVerification::Engine workflow.admin_engine = Decidim::Verifications::SmsVerification::AdminEngine end
Inside these engines, you can implement any steps required for the authorization to succeed, via one or more custom controllers and views. You can create partial
Authorization
records (with theverified_at
column set tonil
) and hold partial verification data in theverification_metadata
column, or even a partial verification attachment in theverification_attachment
column.Decidim currently requires that your main engine defines two routes:
new_authorization_path
: This is the entry point to start the authorization process.edit_authorization_path
: This is the entry point to resume an existing authorization process.
Custom action authorizers
Custom action authorizers are an advanced feature that can be used in both types of authorization methods to customize some parts of the authorization process. These are particulary useful when used within verification options, which are set in the admin zone related to a feature action. As a result, a verification method will be allowed to change the authorization logic and the appearance based on the context where the authorization is being performed.
For example, you can require authorization for supporting proposals in a participatory
process, and also restrict it to users with postal codes 12345 and 12346. The
example authorization handler
included in this module allows to do that. As an admin user, you should visit
the proposals componenent permissions screen, choose the Example authorization
as the authorization handler name for the vote
action and type something like
{ allowed_postal_codes: ["12345", "12346"] }
in the Options
field placed below.
You can override default behavior implementing a class that inherits form
Decidim::Verifications::DefaultActionAuthorizer
and override some methods or that
implement its public methods:
The
initialize
method receives the current authorization process context and saves it in local variables. This include the current authorization user state (anAuthorization
record) and permissionoptions
related to the action is trying to perform.The
authorize
method is responsible of evaluating the authorization process context and determine if the user authorization is:ok
or in any other status.The
redirect_params
method allows to add additional query string parameters when redirecting to the authorization form. This is useful to send to the authorization form the permissionoptions
information that could be useful to adapt its behavior or appearance.
To be used by the verification method, this class should be referenced by name in its workflow manifest:
# config/initializers/decidim.rb
Decidim::Verifications.register_workflow(:sms_verification) do |workflow|
workflow.engine = Decidim::Verifications::SmsVerification::Engine
workflow.admin_engine = Decidim::Verifications::SmsVerification::AdminEngine
workflow.action_authorizer = "Decidim::Verifications::SmsVerification::ActionAuthorizer"
end
Check the example authorization handler and the DefaultActionAuthorizer class for additional technical details.
Installation
Add this line to your application's Gemfile:
gem 'decidim-verifications'
And then execute:
bundle
Contributing
See Decidim.
License
See Decidim.