Catalyst-Plugin-OIDC
view release on metacpan or search on metacpan
lib/Catalyst/Plugin/OIDC.pm view on Meta::CPAN
package Catalyst::Plugin::OIDC;
use utf8;
use Moose;
use namespace::autoclean;
with 'Catalyst::ClassData';
use feature 'signatures';
no warnings 'experimental::signatures';
use Catalyst::Action;
use Carp qw(croak);
use Clone qw(clone);
use List::Util qw(first);
use Scalar::Util qw(blessed);
use Try::Tiny;
use OIDC::Client;
use OIDC::Client::Plugin;
use OIDC::Client::Error;
use OIDC::Client::Error::Authentication;
our $VERSION = '1.03'; # VERSION: generated by Dist::Zilla::Plugin::OurPkgVersion
=encoding utf8
=head1 NAME
Catalyst::Plugin::OIDC - OIDC protocol integration for Catalyst
=head1 DESCRIPTION
This plugin makes it easy to integrate the OpenID Connect protocol
into a Catalyst application.
It essentially uses the L<OIDC-Client|https://metacpan.org/dist/OIDC-Client>
distribution.
=cut
__PACKAGE__->mk_classdata('_oidc_config');
__PACKAGE__->mk_classdata('_oidc_client_by_provider');
=head1 METHODS
=head2 setup_finalize
Code executed once when the application is loaded.
Depending on the configuration, creates and keeps in memory one or more clients
(L<OIDC::Client> stateless objects) and automatically adds the callback routes
to the application.
=cut
sub setup_finalize ($app) {
my $config = $app->config->{'oidc_client'}
or croak('no oidc_client config');
$app->_oidc_config($config);
my %client_by_provider;
my %seen_path;
my $dispatch_path = first { $_->isa('Catalyst::DispatchType::Path') } @{$app->dispatcher->dispatch_types};
foreach my $provider (keys %{ $config->{provider} || {} }) {
my $config_provider = clone($config->{provider}{$provider});
$config_provider->{provider} = $provider;
$client_by_provider{$provider} = OIDC::Client->new(
config => $config_provider,
log => $app->log,
);
( run in 1.189 second using v1.01-cache-2.11-cpan-39bf76dae61 )