NAME

Plack::Auth::SSO::OIDC - implementation of OpenID Connect for Plack::Auth::SSO

STATUS

Build Status Coverage CPANTS kwalitee

DESCRIPTION

This is an implementation of Plack::Auth::SSO to authenticate against a openid connect server.

It inherits all configuration options from its parent.

SYNOPSIS

# in your app.psi (Plack)

use strict;
use warnings;
use Plack::Builder;
use JSON;
use Plack::Auth::SSO::OIDC;
use Plack::Session::Store::File;

my $uri_base = "http://localhost:5000";

builder {

    # session middleware needed to store "auth_sso" and/or "auth_sso_error"
    # in memory session store for testing purposes
    enable "Session";

    # for authentication, redirect your users to this path
    mount "/auth/oidc" => Plack::Auth::SSO::OIDC->new(

        # plack application needs to know about the base url of this application
        uri_base => $uri_base,

        # after successfull authentication, user is redirected to this path (uri_base is used!)
        authorization_path => "/auth/callback",

        # when authentication fails at the identity provider
        # user is redirected to this path with session key "auth_sso_error" (hash)
        error_path => "/auth/error",

        # openid connect discovery url
        openid_uri => "https://example.oidc.org/auth/oidc/.well-known/openid-configuration",
        client_id => "my-client-id",
        client_secret => "myclient-secret",
        uid_key => "email"

    )->to_app();

    # example psgi app that is called after successfull authentication at /auth/oidc (see above)
    # it expects session key "auth_sso" to be present
    # here you typically create a user session based on the uid in "auth_sso"
    mount "/auth/callback" => sub {

        my $env     = shift;
        my $session = Plack::Session->new($env);
        my $auth_sso= $session->get("auth_sso");
        my $user    = MyUsers->get( $auth_sso->{uid} );
        $session->set("user_id", $user->{id});
        [ 200, [ "Content-Type" => "text/plain" ], [
            "logged in! ", $user->{name}
        ]];

    };

    # example psgi app that is called after unsuccessfull authentication at /auth/oidc (see above)
    # it expects session key "auth_sso_error" to be present
    mount "/auth/error" => sub {

        my $env = shift;
        my $session = Plack::Session->new($env);
        my $auth_sso_error = $session->get("auth_sso_error");

        [ 200, [ "Content-Type" => "text/plain" ], [
            "something happened during single sign on authentication: ",
            $auth_sso_error->{content}
        ]];

    };
};

CONSTRUCTOR ARGUMENTS

HOW IT WORKS

NOTES

LOGGING

All subclasses of Plack::Auth::SSO use Log::Any to log messages to the category that equals the current package name.

AUTHOR

Nicolas Franck, <nicolas.franck at ugent.be>

LICENSE AND COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

SEE ALSO

Plack::Auth::SSO