Use eval to decode JSON content (#183)
This commit is contained in:
parent
914fe20eb5
commit
c64f69a852
@ -7,7 +7,6 @@ package Lemonldap::NG::Portal::AuthOpenIDConnect;
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use Lemonldap::NG::Portal::Simple;
|
use Lemonldap::NG::Portal::Simple;
|
||||||
use JSON;
|
|
||||||
use MIME::Base64;
|
use MIME::Base64;
|
||||||
use base qw(Lemonldap::NG::Portal::_OpenIDConnect);
|
use base qw(Lemonldap::NG::Portal::_OpenIDConnect);
|
||||||
|
|
||||||
@ -79,7 +78,7 @@ sub extractFormInfo {
|
|||||||
my $content = $self->getAuthorizationCodeAccessToken($code);
|
my $content = $self->getAuthorizationCodeAccessToken($code);
|
||||||
return PE_ERROR unless $content;
|
return PE_ERROR unless $content;
|
||||||
|
|
||||||
my $json = decode_json $content;
|
my $json = $self->decodeJSON($content);
|
||||||
|
|
||||||
if ( $json->{error} ) {
|
if ( $json->{error} ) {
|
||||||
$self->lmLog( "Error in token response:" . $json->{error},
|
$self->lmLog( "Error in token response:" . $json->{error},
|
||||||
@ -99,9 +98,8 @@ sub extractFormInfo {
|
|||||||
my ( $id_token_header, $id_token_payload, $id_token_signature ) =
|
my ( $id_token_header, $id_token_payload, $id_token_signature ) =
|
||||||
split( /\./, $id_token );
|
split( /\./, $id_token );
|
||||||
|
|
||||||
# TODO check signature
|
|
||||||
my $id_token_payload_hash =
|
my $id_token_payload_hash =
|
||||||
decode_json( decode_base64($id_token_payload) );
|
$self->decodeJSON( decode_base64($id_token_payload) );
|
||||||
|
|
||||||
my $user_id = $id_token_payload_hash->{sub};
|
my $user_id = $id_token_payload_hash->{sub};
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ sub getCallbackUri {
|
|||||||
return $callback_uri;
|
return $callback_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
## @method Strind buildAuthorizationCodeAuthnRequest(String state)
|
## @method String buildAuthorizationCodeAuthnRequest(String state)
|
||||||
# Build Authentication Request URI for Authorization Code Flow
|
# Build Authentication Request URI for Authorization Code Flow
|
||||||
# @param state State
|
# @param state State
|
||||||
# return String Authentication Request URI
|
# return String Authentication Request URI
|
||||||
@ -66,7 +66,7 @@ sub buildAuthorizationCodeAuthnRequest {
|
|||||||
return $authn_uri;
|
return $authn_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
## @method Strind getAuthorizationCodeAccessToken(String code)
|
## @method String getAuthorizationCodeAccessToken(String code)
|
||||||
# Get Token response with autorization code
|
# Get Token response with autorization code
|
||||||
# @param code Code
|
# @param code Code
|
||||||
# return String Token response decoded content
|
# return String Token response decoded content
|
||||||
@ -99,6 +99,23 @@ sub getAuthorizationCodeAccessToken {
|
|||||||
return $response->decoded_content;
|
return $response->decoded_content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## @method HashRef decodeJSON(String json)
|
||||||
|
# Convert JSON to HashRef
|
||||||
|
# @param json JSON raw content
|
||||||
|
# @return HashRef JSON decoded content
|
||||||
|
sub decodeJSON {
|
||||||
|
my ( $self, $json ) = splice @_;
|
||||||
|
my $json_hash;
|
||||||
|
|
||||||
|
eval { $json_hash = decode_json $json; };
|
||||||
|
|
||||||
|
if ($@) {
|
||||||
|
$json_hash->{error} = "parse_error";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $json_hash;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
@ -132,6 +149,10 @@ Build Authentication Request URI for Authorization Code Flow
|
|||||||
|
|
||||||
Get Token response with autorization code
|
Get Token response with autorization code
|
||||||
|
|
||||||
|
=head2 decodeJSON
|
||||||
|
|
||||||
|
Convert JSON to HashRef
|
||||||
|
|
||||||
=head1 SEE ALSO
|
=head1 SEE ALSO
|
||||||
|
|
||||||
L<Lemonldap::NG::Portal::AuthOpenIDConnect>, L<Lemonldap::NG::Portal::UserDBOpenIDConnect>
|
L<Lemonldap::NG::Portal::AuthOpenIDConnect>, L<Lemonldap::NG::Portal::UserDBOpenIDConnect>
|
||||||
|
Loading…
Reference in New Issue
Block a user