Commit a5b3f2b6 authored by Clément OUDOT's avatar Clément OUDOT

Request UserInfo endpoint to get Google attributes (#LEMONLDAP-807)

git-svn-id: svn://svn.forge.objectweb.org/svnroot/lemonldap/branches/lemonldap-ng_version_1_4-bugfixes@3714 1dbb9719-a921-0410-b57f-c3a383c2c641
parent 2f5742e9
......@@ -51,6 +51,12 @@ sub extractFormInfo {
my $redirect_uri = $self->{portal} . "?googlecb=1";
my $state = encode_base64url( $self->{urldc} );
# Ask for profile if googleExportedVars requested
my %vars = ( %{ $self->{exportedVars} }, %{ $self->{googleExportedVars} } );
if (%vars) {
$scope .= " profile";
}
my $callback = $self->param("googlecb");
if ($callback) {
......@@ -100,6 +106,35 @@ sub extractFormInfo {
$self->{urldc} = decode_base64url( $self->param("state") );
}
if (%vars) {
# Request UserInfo
my $ui_response = $self->ua->get(
"https://www.googleapis.com/oauth2/v3/userinfo",
"Authorization" => "Bearer $access_token"
);
my $ui_content = $ui_response->decoded_content;
my $ui_json;
eval { $ui_json = decode_json($ui_content); };
# Convert OpenID attribute name into OIDC UserInfo field
my $convertAttr = {
"firstname" => "given_name",
"lastname" => "family_name",
"language" => "locale",
"email" => "email",
};
# Store attributes in session
while ( my ( $k, $v ) = each %vars ) {
my $attr = $k;
$attr =~ s/^!//;
my $oidc_attr = $convertAttr->{$v};
$self->{sessionInfo}->{$attr} = $ui_json->{$oidc_attr};
}
}
return PE_OK;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment