From 7a61750eb3ea41bf9d598b48689b9bc4570b121a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20OUDOT?= Date: Wed, 4 Dec 2019 17:50:41 +0100 Subject: [PATCH] Start OIDC RP API (#2034) --- .../lib/Lemonldap/NG/Manager/Api.pm | 23 +++++++---- .../lib/Lemonldap/NG/Manager/Api/Providers.pm | 39 +++++++++++++++++++ 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api.pm index 735511589..3e32e805e 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api.pm @@ -25,13 +25,22 @@ sub addRoutes { $self->addRoute( 'api.html', undef, ['GET'] ) ->addRoute( - api => { - v1 => { - hello => "helloworld", - }, - }, - ['GET'] + api => { + v1 => { + hello => "helloworld", + }, + }, + ['GET'] + ) + + ->addRoute( + providers => { + oidc => { + rp => { ':confKey' => 'getOidcRpByConfKey' }, + }, + }, + ['GET'] ); - } +} 1; diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api/Providers.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api/Providers.pm index 1cf5544cb..70de4eb72 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api/Providers.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api/Providers.pm @@ -3,4 +3,43 @@ our $VERSION = '2.0.7'; package Lemonldap::NG::Manager::Api; +sub getOidcRpByConfKey { + my ( $self, $req ) = @_; + + my $confKey = $req->params('confKey') + or return $self->sendError( $req, 'confKey is missing', 400 ); + + $self->logger->debug("[API] OIDC RP $confKey configuration requested"); + + # Get latest configuration + my $conf = $self->_confAcc->getConf; + + # To save configuration + #$self->_confAcc->saveConf( $conf ) ; + + # Dump object + #use Data::Dumper; print STDERR Dumper($self); + + # Check if confKey is defined + if ( !defined $conf->{oidcRPMetaDataOptions}->{$confKey} ) { + return $self->sendError( $req, 'Service Provider not found', 404 ); + } + + # Get Client ID + my $clientId = $conf->{oidcRPMetaDataOptions}->{$confKey} + ->{oidcRPMetaDataOptionsClientID}; + + # Get exported vars + my $exportedVars = $conf->{oidcRPMetaDataExportedVars}->{$confKey}; + + return $self->sendJSONresponse( + $req, + { + confKey => $confKey, + clientId => $clientId, + exportedVars => $exportedVars + } + ); +} + 1;