Merge pull request #449 from kanji-keraliya/office-365-integration-domain
Fixed: Office 365 integration redirection URL issue
This commit is contained in:
		
						commit
						ceacf02383
					
				
					 2 changed files with 2 additions and 8 deletions
				
			
		|  | @ -21,13 +21,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) | ||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         const hostname = 'x-forwarded-host' in req.headers ? 'https://' + req.headers['x-forwarded-host'] : 'host' in req.headers ? (req.secure ? 'https://' : 'http://') + req.headers['host'] : ''; |  | ||||||
|         if ( ! hostname || ! req.headers.referer.startsWith(hostname)) { |  | ||||||
|             throw new Error('Unable to determine external url, check server settings'); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         function generateAuthUrl() { |         function generateAuthUrl() { | ||||||
|             return 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?response_type=code&scope=' + scopes.join(' ') + '&client_id=' + process.env.MS_GRAPH_CLIENT_ID + '&redirect_uri=' + hostname + '/api/integrations/office365calendar/callback'; |             return 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?response_type=code&scope=' + scopes.join(' ') + '&client_id=' + process.env.MS_GRAPH_CLIENT_ID + '&redirect_uri=' + process.env.BASE_URL + '/api/integrations/office365calendar/callback'; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         res.status(200).json({url: generateAuthUrl() }); |         res.status(200).json({url: generateAuthUrl() }); | ||||||
|  |  | ||||||
|  | @ -11,9 +11,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) | ||||||
|     if (!session) { res.status(401).json({message: 'You must be logged in to do this'}); return; } |     if (!session) { res.status(401).json({message: 'You must be logged in to do this'}); return; } | ||||||
| 
 | 
 | ||||||
|     const toUrlEncoded = payload => Object.keys(payload).map( (key) => key + '=' + encodeURIComponent(payload[ key ]) ).join('&'); |     const toUrlEncoded = payload => Object.keys(payload).map( (key) => key + '=' + encodeURIComponent(payload[ key ]) ).join('&'); | ||||||
|     const hostname = 'x-forwarded-host' in req.headers ? 'https://' + req.headers['x-forwarded-host'] : 'host' in req.headers ? (req.secure ? 'https://' : 'http://') + req.headers['host'] : ''; |  | ||||||
| 
 | 
 | ||||||
|     const body = toUrlEncoded({ client_id: process.env.MS_GRAPH_CLIENT_ID, grant_type: 'authorization_code', code, scope: scopes.join(' '), redirect_uri: hostname + '/api/integrations/office365calendar/callback', client_secret: process.env.MS_GRAPH_CLIENT_SECRET }); |     const body = toUrlEncoded({ client_id: process.env.MS_GRAPH_CLIENT_ID, grant_type: 'authorization_code', code, scope: scopes.join(' '), redirect_uri: process.env.BASE_URL + '/api/integrations/office365calendar/callback', client_secret: process.env.MS_GRAPH_CLIENT_SECRET }); | ||||||
| 
 | 
 | ||||||
|     const response = await fetch('https://login.microsoftonline.com/common/oauth2/v2.0/token', { method: 'POST', headers: { |     const response = await fetch('https://login.microsoftonline.com/common/oauth2/v2.0/token', { method: 'POST', headers: { | ||||||
|         'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', |         'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Bailey Pumfleet
						Bailey Pumfleet