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

75 lines
1.5 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_BADCREDENTIALS
PE_OK
);
2019-02-12 18:21:38 +01:00
our $VERSION = '2.1.0';
2016-12-30 08:03:48 +01:00
2017-02-15 07:41:50 +01:00
extends '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
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;
}
2017-02-15 07:41:50 +01:00
$self->logger->debug("UserInfo received: $userinfo_content");
2016-12-30 08:03:48 +01:00
$req->data->{OpenIDConnect_user_info} =
2016-12-30 08:03:48 +01:00
$self->decodeJSON($userinfo_content);
# 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;
}
# 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
|| "";
}
PE_OK;
}
# Does nothing
sub setGroups {
PE_OK;
}
1;