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.05'; # 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 enables applications to act as an
OpenID Connect Relying Party (RP) for user authentication and as an
OAuth 2.0 Resource Server by validating Access Tokens issued by an
external Authorization Server or OpenID Provider. It does not implement
an OpenID Provider.

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(



( run in 2.039 seconds using v1.01-cache-2.11-cpan-5fbc6bb55f2 )