File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1087,15 +1087,27 @@ OpenIDConnect.prototype.userInfo = function() {
10871087 . exec ( function ( err , access ) {
10881088 if ( ! err && access ) {
10891089 req . model . user . findOne ( { id : access . user } , function ( err , user ) {
1090- if ( req . check . scopes . indexOf ( 'profile' ) != - 1 ) {
1091- user . sub = req . session . sub || req . session . user ;
1090+ // 2.3.2. "The sub (subject) Claim MUST always be returned in the UserInfo Response."
1091+ if ( typeof user . sub === 'function' ) {
1092+ user . sub = user . sub ( ) ;
1093+ }
1094+ if ( req . check . scopes . indexOf ( 'profile' ) !== - 1 ) {
10921095 delete user . id ;
10931096 delete user . password ;
10941097 delete user . openidProvider ;
1095- res . json ( user ) ;
1096- } else {
1097- res . json ( { email : user . email } ) ;
10981098 }
1099+ else {
1100+ user = {
1101+ sub : user . sub ,
1102+ email : user . email ,
1103+ email_verified : user . email_verified ,
1104+ } ;
1105+ }
1106+ if ( req . check . scopes . indexOf ( 'email' ) === - 1 ) {
1107+ delete user . email ;
1108+ delete user . email_verified ;
1109+ }
1110+ res . json ( user ) ;
10991111 } ) ;
11001112 } else {
11011113 self . errorHandle ( res , null , 'unauthorized_client' , 'Access token is not valid.' ) ;
You can’t perform that action at this time.
0 commit comments