Dancer2-Plugin-SPID

 view release on metacpan or  search on metacpan

lib/Dancer2/Plugin/SPID.pm  view on Meta::CPAN

                if ($logoutreq->session eq $self->spid_session->session) {
                    # Call the hook *before* clearing spid_session.
                    $self->execute_plugin_hook('after_logout', 'success');
                    
                    $self->dsl->session('__spid_session' => undef);
                } else {
                    $status = 'partial';
                    $self->dsl->warning(
                        sprintf "SAML LogoutRequest session (%s) does not match current SPID session (%s)",
                            $logoutreq->session, $self->spid_session->session
                    );
                }
                
                # Craft a LogoutResponse and send it back to the Identity Provider.
                my $logoutres = $logoutreq->make_response(status => $status);
    
                # Redirect user to the Identity Provider; it will continue handling the logout process.
                $self->dsl->redirect($logoutres->redirect_url, 302);
            } else {
                $self->dsl->status(400);
            }
        },
    );
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Dancer2::Plugin::SPID - SPID authentication for Dancer2 web applications

=head1 VERSION

version 0.11

=head1 SYNOPSIS

    use Dancer2;
    use Dancer2::Plugin::SPID;
    
    hook 'plugin.SPID.after_login' => sub {
        # log assertion:
        info "User " . spid_session->nameid . " logged in";
        info "SPID Assertion: " . spid_session->assertion_xml;
    };
    
    hook 'plugin.SPID.after_logout' => sub {
        debug "User " . spid_session->nameid . " logged out";
    };

    dance;

=head1 ABSTRACT

This Perl module is a plugin for the L<Dancer2> web framework. It allows developers of SPID Service Providers to easily add SPID authentication to their Dancer2 applications. L<SPID|https://www.spid.gov.it/> is the Italian digital identity system, wh...

This module provides the highest level of abstraction and ease of use for integration of SPID in a Dancer2 web application. Just set a few configuration options and you'll be able to generate the HTML markup for the SPID button on the fly (to be comp...

See the F<example/> directory for a demo application.

This is module is based on L<Net::SPID> which provides the lower-level framework-independent implementation of SPID for Perl.

=head1 CONFIGURATION

Configuration options can be set in the Dancer2 config file:

    plugins:
      SPID:
        sp_entityid: "https://www.prova.it/"
        sp_key_file: "sp.key"
        sp_cert_file: "sp.pem"
        sp_assertionconsumerservice:
          - "http://localhost:3000/spid-sso"
        sp_singlelogoutservice:
          "http://localhost:3000/spid-slo": "HTTP-Redirect"
        idp_metadata_dir: "idp_metadata/"
        login_endpoint: "/spid-login"
        logout_endpoint: "/spid-logout"
        sso_endpoint: "/spid-sso"
        slo_endpoint: "/spid-slo"

=over

=item I<sp_entityid>

(Required.) The entityID value for this Service Provider. According to SPID regulations, this should be a URI.

=item I<sp_key_file>

(Required.) The absolute or relative file path to our private key file.

=item I<sp_cert_file>

(Required.) The absolute or relative file path to our certificate file.

=item I<sp_assertionconsumerservice>

An arrayref with the URL(s) of our AssertionConsumerService endpoint(s). It is used for metadata generation and for validating the C<Destination> XML attribute of the incoming responses.

=item I<sp_singlelogoutservice>

A hashref with the URL(s) of our SingleLogoutService endpoint(s), along with the specification of the binding. It is used for metadata generation and for validating the C<Destination> XML attribute of the incoming responses.

=item I<sp_attributeconsumingservice>

(Optional.) An arrayref with the AttributeConsumingServices to list in metadata, each one described by a C<servicename> and a list of C<attributes>. This is optional as it's only used for metadata generation.

    sp_attributeconsumingservice:
      - servicename: "Service 1"
        attributes:
          - "fiscalNumber"
          - "name"
          - "familyName"
          - "dateOfBirth"



( run in 0.326 second using v1.01-cache-2.11-cpan-d7f47b0818f )