Search code examples
phphtmlgoogle-oauth

PHPMailer getOAuth2token response to div


Is there a way to redirect the output of PHPMailer's get_oauth_token.php (https://github.com/PHPMailer/PHPMailer/blob/master/get_oauth_token.php) into an adot div? I pasted the file from github into an mvc-based program that is being prepared.

The script runs nicely, then when the header( 'Location: ' . $authUrl ); reaches line, refreshes the whole page: localhost/Admin/getOAuth2Token?state=...

Or when you are redirected to Google's page on the first invitation, due to connecting and enabling the program to your account. I would like to load this into a specified div, if possible, so that I can stay within the page.


Solution

  • This is a redirect back to your site, so you can not have that "stay within the same page."

    You could try and open the auth URL in a popup though; and then, when the user has been redirected back to your redirect_uri within the popup, you can have the popup communicate with the opening window using postMessage, and then close the popup. (Assuming you still get access to window.opener after the redirect back, not sure, you'd have to test that. But f.e. Facebook manages to implement the same process for their client-side login flow, so it should be possible.)