lemonldap-ng/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/OpenIDConnect.pm

93 lines
1.9 KiB
Perl
Raw Normal View History

2016-12-30 08:03:48 +01:00
package Lemonldap::NG::Portal::UserDB::OpenIDConnect;
use strict;
use Mouse;
use Lemonldap::NG::Portal::Main::Constants qw(
PE_OIDC_AUTH_ERROR
2016-12-30 08:03:48 +01:00
PE_BADCREDENTIALS
PE_ERROR
2016-12-30 08:03:48 +01:00
PE_OK
);
2021-04-01 23:07:58 +02:00
our $VERSION = '2.0.12';
2016-12-30 08:03:48 +01:00
2021-04-01 23:07:58 +02:00
extends qw(
Lemonldap::NG::Common::Module
Lemonldap::NG::Portal::Lib::OpenIDConnect
);
2016-12-30 08:03:48 +01:00
# INITIALIZATION
sub init {
my ($self) = @_;
2017-01-01 10:43:48 +01:00
return $self->loadOPs;
2016-12-30 08:03:48 +01:00
}
# RUNNING METHODS
sub getUser {
my ( $self, $req ) = @_;
my $op = $req->data->{_oidcOPCurrent};
2016-12-30 08:03:48 +01:00
# This is likely to happen when running getUser without extractFormInfo
# see #1980
unless ($op) {
$self->logger->warn("No OP found in current session");
return PE_ERROR;
}
my $access_token = $req->data->{access_token};
2016-12-30 08:03:48 +01:00
my $userinfo_content = $self->getUserInfo( $op, $access_token );
unless ($userinfo_content) {
2017-02-15 07:41:50 +01:00
$self->logger->warn("No User Info content");
2016-12-30 08:03:48 +01:00
return PE_OK;
}
# call oidcGotUserInfo hook
my $h =
$self->p->processHook( $req, 'oidcGotUserInfo', $op, $userinfo_content, );
return PE_OIDC_AUTH_ERROR if ( $h != PE_OK );
$req->data->{OpenIDConnect_user_info} = $userinfo_content;
2016-12-30 08:03:48 +01:00
# Check that received sub is the same than current user
unless ( $req->data->{OpenIDConnect_user_info}->{sub} eq $req->{user} ) {
2017-02-15 07:41:50 +01:00
$self->logger->error("Received sub do not match current user");
2016-12-30 08:03:48 +01:00
return PE_BADCREDENTIALS;
}
return PE_OK;
}
2020-12-22 15:17:23 +01:00
sub findUser {
# Nothing to do here
2021-04-01 23:07:58 +02:00
return PE_OK;
2020-12-22 15:17:23 +01:00
}
2016-12-30 08:03:48 +01:00
# Get all required attributes
sub setSessionInfo {
my ( $self, $req ) = @_;
my $op = $req->data->{_oidcOPCurrent};
2016-12-30 08:03:48 +01:00
my %vars = (
%{ $self->conf->{exportedVars} },
%{ $self->conf->{oidcOPMetaDataExportedVars}->{$op} }
);
while ( my ( $k, $v ) = each %vars ) {
$req->{sessionInfo}->{$k} = $req->data->{OpenIDConnect_user_info}->{$v};
2016-12-30 08:03:48 +01:00
}
2021-04-01 23:07:58 +02:00
return PE_OK;
2016-12-30 08:03:48 +01:00
}
# Does nothing
sub setGroups {
2021-04-01 23:07:58 +02:00
return PE_OK;
2016-12-30 08:03:48 +01:00
}
1;