@@ -694,7 +694,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
694
694
userName : string ,
695
695
password : string ,
696
696
headers : HttpHeaders = new HttpHeaders ( )
697
- ) : Promise < UserInfo > {
697
+ ) : Promise < UserInfo | string > {
698
698
return this . fetchTokenUsingPasswordFlow (
699
699
userName ,
700
700
password ,
@@ -708,7 +708,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
708
708
* When using this with OAuth2 password flow, make sure that the property oidc is set to false.
709
709
* Otherwise stricter validations take place that make this operation fail.
710
710
*/
711
- public loadUserProfile ( ) : Promise < UserInfo > {
711
+ public loadUserProfile ( ) : Promise < UserInfo | string > {
712
712
if ( ! this . hasValidAccessToken ( ) ) {
713
713
throw new Error ( 'Can not load User Profile without access_token' ) ;
714
714
}
@@ -725,35 +725,54 @@ export class OAuthService extends AuthConfig implements OnDestroy {
725
725
) ;
726
726
727
727
this . http
728
- . get < UserInfo > ( this . userinfoEndpoint , { headers } )
728
+ . get ( this . userinfoEndpoint , {
729
+ headers,
730
+ observe : 'response' ,
731
+ responseType : 'text'
732
+ } )
729
733
. subscribe (
730
- info => {
731
- this . debug ( 'userinfo received' , info ) ;
732
-
733
- const existingClaims = this . getIdentityClaims ( ) || { } ;
734
-
735
- if ( ! this . skipSubjectCheck ) {
736
- if (
737
- this . oidc &&
738
- ( ! existingClaims [ 'sub' ] || info . sub !== existingClaims [ 'sub' ] )
739
- ) {
740
- const err =
741
- 'if property oidc is true, the received user-id (sub) has to be the user-id ' +
742
- 'of the user that has logged in with oidc.\n' +
743
- 'if you are not using oidc but just oauth2 password flow set oidc to false' ;
744
-
745
- reject ( err ) ;
746
- return ;
734
+ response => {
735
+ this . debug ( 'userinfo received' , JSON . stringify ( response ) ) ;
736
+ if (
737
+ response . headers
738
+ . get ( 'content-type' )
739
+ . startsWith ( 'application/json' )
740
+ ) {
741
+ let info = response . body ;
742
+ const existingClaims = this . getIdentityClaims ( ) || { } ;
743
+
744
+ if ( ! this . skipSubjectCheck ) {
745
+ if (
746
+ this . oidc &&
747
+ ( ! existingClaims [ 'sub' ] || info . sub !== existingClaims [ 'sub' ] )
748
+ ) {
749
+ const err =
750
+ 'if property oidc is true, the received user-id (sub) has to be the user-id ' +
751
+ 'of the user that has logged in with oidc.\n' +
752
+ 'if you are not using oidc but just oauth2 password flow set oidc to false' ;
753
+
754
+ reject ( err ) ;
755
+ return ;
756
+ }
747
757
}
748
- }
749
758
750
- info = Object . assign ( { } , existingClaims , info ) ;
759
+ info = Object . assign ( { } , existingClaims , info ) ;
751
760
752
- this . _storage . setItem ( 'id_token_claims_obj' , JSON . stringify ( info ) ) ;
753
- this . eventsSubject . next (
754
- new OAuthSuccessEvent ( 'user_profile_loaded' )
755
- ) ;
756
- resolve ( info ) ;
761
+ this . _storage . setItem (
762
+ 'id_token_claims_obj' ,
763
+ JSON . stringify ( info )
764
+ ) ;
765
+ this . eventsSubject . next (
766
+ new OAuthSuccessEvent ( 'user_profile_loaded' )
767
+ ) ;
768
+ resolve ( info ) ;
769
+ } else {
770
+ this . debug ( 'userinfo is not JSON, treating it as JWE/JWS' ) ;
771
+ this . eventsSubject . next (
772
+ new OAuthSuccessEvent ( 'user_profile_loaded' )
773
+ ) ;
774
+ resolve ( response . body ) ;
775
+ }
757
776
} ,
758
777
err => {
759
778
this . logger . error ( 'error loading user info' , err ) ;
0 commit comments