Fixed bug where null email address could occurr in office365 credential key
This commit is contained in:
		
							parent
							
								
									2b84612e5d
								
							
						
					
					
						commit
						27194ef68c
					
				
					 1 changed files with 2 additions and 1 deletions
				
			
		|  | @ -28,7 +28,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) | ||||||
|     const whoami = await fetch('https://graph.microsoft.com/v1.0/me', { headers: { 'Authorization': 'Bearer ' + responseBody.access_token } }); |     const whoami = await fetch('https://graph.microsoft.com/v1.0/me', { headers: { 'Authorization': 'Bearer ' + responseBody.access_token } }); | ||||||
|     const graphUser = await whoami.json(); |     const graphUser = await whoami.json(); | ||||||
| 
 | 
 | ||||||
|     responseBody.email = graphUser.mail; |     // In some cases, graphUser.mail is null. Then graphUser.userPrincipalName most likely contains the email address.
 | ||||||
|  |     responseBody.email = graphUser.mail ?? graphUser.userPrincipalName; | ||||||
|     responseBody.expiry_date = Math.round((+(new Date()) / 1000) + responseBody.expires_in); // set expiry date in seconds
 |     responseBody.expiry_date = Math.round((+(new Date()) / 1000) + responseBody.expires_in); // set expiry date in seconds
 | ||||||
|     delete responseBody.expires_in; |     delete responseBody.expires_in; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 nicolas
						nicolas