You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
We are trying to configure OJS for Gmail SMTP as we have acquired Google workspace services and want OJS to send email via google workspace instead of the local mail server. We configured the config.inc.php file as guided here: https://docs.pkp.sfu.ca/admin-guide/en/email#configuring-the-system-to-use-gmail-smtp . In config.inc.php our email settings are provided in additional information. However, email sending error happened, so we tried to configure Gmail with XOAUTH2 and followed the process as guided here: https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2 . However, when we run the get_oauth_token.php in browser and select the provider as google, then sign in (with same account from where we generated client ID), and then allow the permissions, it redirects us to the OJS homepage instead of showing the refresh token. We have tried to reach PHPMailer support and link to their ongoing response is: PHPMailer/PHPMailer#2646.
Go to 'sub_domain.my_domain_name.com/lib/pkp/lib/vendor/phpmailer/phpmailer/get_oauth_token.php'
Click on 'select provider as google'
Sign in with Google 'used the same email from where generated the client ID and secret'
Allow access to user account
Redirects to: 'sub_domain.my_domain_name.com/index.php/journal
What application are you using?
OJS, version 3.3.0.7.
Additional information Email settings in config.inc.php:
`[email]
; Use SMTP for sending mail instead of mail()
smtp = On
; SMTP server settings
smtp_server = smtp.gmail.com
smtp_port = 465
; Enable SMTP authentication
; Supported smtp_auth: ssl, tls (see PHPMailer SMTPSecure)
smtp_auth = ssl
smtp_username = "my_email@my_domain_name.com"
smtp_password = "my_email_password"
;
; Supported smtp_authtype: RAM-MD5, LOGIN, PLAIN, XOAUTH2 (see PHPMailer AuthType)
; (Leave blank to try them in that order)
; smtp_authtype =
; The following are required for smtp_authtype = XOAUTH2 (e.g. GMail OAuth)
; (See https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2)
; smtp_oauth_provider = Google
; smtp_oauth_email =
; smtp_oauth_clientid =
; smtp_oauth_clientsecret =
; smtp_oauth_refreshtoken =
; Enable suppressing verification of SMTP certificate in PHPMailer
; Note: this is not recommended per PHPMailer documentation
; smtp_suppress_cert_check = On
` The code in get_oauth_token.php:
`<?php
/**
PHPMailer - PHP email creation and transport class.
if (array_key_exists('provider', $_GET)) {
$providerName = $_GET['provider'];
$_SESSION['provider'] = $providerName;
} elseif (array_key_exists('provider', $_SESSION)) {
$providerName = $_SESSION['provider'];
}
if (!in_array($providerName, ['Google', 'Microsoft', 'Yahoo'])) {
exit('Only Google, Microsoft and Yahoo OAuth2 providers are currently supported in this script.');
}
//These details are obtained by setting up an app in the Google developer console,
//or whichever provider you're using.
$clientId = 'my_client_id.apps.googleusercontent.com';
$clientSecret = 'my_client_secret';
//If this automatic URL doesn't work, set it yourself manually to the URL of this script
//$redirectUri = (isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$redirectUri = 'https://subdomain.my_domain_name.com/lib/pkp/lib/vendor/phpmailer/phpmailer/get_oauth_token.php';
switch ($providerName) {
case 'Google':
$provider = new Google($params);
$options = [
'scope' => [
'https://mail.google.com/'
]
];
break;
case 'Yahoo':
$provider = new Yahoo($params);
break;
case 'Microsoft':
$provider = new Microsoft($params);
$options = [
'scope' => [
'wl.imap',
'wl.offline_access'
]
];
break;
}
if (null === $provider) {
exit('Provider missing');
}
if (!isset($_GET['code'])) {
// If we don't have an authorization code then get one
$authUrl = $provider->getAuthorizationUrl($options);
$_SESSION['oauth2state'] = $provider->getState();
header('Location: ' . $authUrl);
exit;
// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
unset($_SESSION['provider']);
exit('Invalid state');
} else {
unset($_SESSION['provider']);
// Try to get an access token (using the authorization code grant)
$token = $provider->getAccessToken(
'authorization_code',
[
'code' => $_GET['code']
]
);
// Use this to interact with an API on the users behalf
// Use this to get a new access token if the old one expires
echo 'Refresh Token: ', $token->getRefreshToken();
}`
The text was updated successfully, but these errors were encountered:
@asmecher yes, I have posted the issue on forum first to get assistance. Now I tried a workaround as suggested by the PHPMailer support i.e.:
I don't know where your issue is, but you probably don't need to make it work on the live site if you can make it work on localhost. Once you have the access and refresh tokens you can install them on your live server where they will work fine. They are not tied to your callback URL. PHPMailer/PHPMailer#2645 (reply in thread)
I was able to fetch the refresh token on localhost. But when I used these in config.inc.php on live website, I was still unable to send email. Error log recorded following errors:
[10-Mar-2022 17:00:36 UTC] PHP Warning: Declaration of EmailReviewerForm::execute($submission) should be compatible with Form::execute(...$functionArgs) in /home/username/public_html/subdomain/lib/pkp/controllers/grid/users/reviewer/form/EmailReviewerForm.inc.php on line 18
[10-Mar-2022 17:00:52 UTC] PHP Warning: Declaration of EmailReviewerForm::execute($submission) should be compatible with Form::execute(...$functionArgs) in /home/username/public_html/subdomain/lib/pkp/controllers/grid/users/reviewer/form/EmailReviewerForm.inc.php on line 18
[10-Mar-2022 17:00:53 UTC] SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
and when PHPMailer support said:
hose declaration errors have nothing to do with PHPMailer?
I am trying to connect via google smtp for months now. the forum response is very slow which I understand as normal in volunteer support programs. So asked here. Anyhow thanks if anyone can help me where I am making a mistake.
Describe the bug
We are trying to configure OJS for Gmail SMTP as we have acquired Google workspace services and want OJS to send email via google workspace instead of the local mail server. We configured the config.inc.php file as guided here: https://docs.pkp.sfu.ca/admin-guide/en/email#configuring-the-system-to-use-gmail-smtp . In config.inc.php our email settings are provided in additional information. However, email sending error happened, so we tried to configure Gmail with XOAUTH2 and followed the process as guided here: https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2 . However, when we run the get_oauth_token.php in browser and select the provider as google, then sign in (with same account from where we generated client ID), and then allow the permissions, it redirects us to the OJS homepage instead of showing the refresh token. We have tried to reach PHPMailer support and link to their ongoing response is: PHPMailer/PHPMailer#2646.
NOTE: In localhost simple configuration as recommended https://docs.pkp.sfu.ca/admin-guide/en/email#configuring-the-system-to-use-gmail-smtp worked and email sent via my_email@gmail.com. Similiarly, in localhost get_oauth_token.php resulted in displaying refresh token and not redirected to homepage as is the case in live website.
To Reproduce
Email settings in config.inc.php as recommended at https://docs.pkp.sfu.ca/admin-guide/en/email#configuring-the-system-to-use-gmail-smtp
For Using Gmail with XOAUTH2 steps followed as recommended at https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2 and at Fetch the token step:
What application are you using?
OJS, version 3.3.0.7.
Additional information
Email settings in config.inc.php:
`[email]
; Use SMTP for sending mail instead of mail()
smtp = On
; SMTP server settings
smtp_server = smtp.gmail.com
smtp_port = 465
; Enable SMTP authentication
; Supported smtp_auth: ssl, tls (see PHPMailer SMTPSecure)
smtp_auth = ssl
smtp_username = "my_email@my_domain_name.com"
smtp_password = "my_email_password"
;
; Supported smtp_authtype: RAM-MD5, LOGIN, PLAIN, XOAUTH2 (see PHPMailer AuthType)
; (Leave blank to try them in that order)
; smtp_authtype =
; The following are required for smtp_authtype = XOAUTH2 (e.g. GMail OAuth)
; (See https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2)
; smtp_oauth_provider = Google
; smtp_oauth_email =
; smtp_oauth_clientid =
; smtp_oauth_clientsecret =
; smtp_oauth_refreshtoken =
; Enable suppressing verification of SMTP certificate in PHPMailer
; Note: this is not recommended per PHPMailer documentation
; smtp_suppress_cert_check = On
`
The code in get_oauth_token.php:
`<?php
/**
*/
/**
*/
namespace PHPMailer\PHPMailer;
/**
composer install
*/
// @see https://github.com/thephpleague/oauth2-google
use League\OAuth2\Client\Provider\Google;
// @see https://packagist.org/packages/hayageek/oauth2-yahoo
use Hayageek\OAuth2\Client\Provider\Yahoo;
// @see https://github.com/stevenmaguire/oauth2-microsoft
use Stevenmaguire\OAuth2\Client\Provider\Microsoft;
if (!isset($_GET['code']) && !isset($_GET['provider'])) {
Select Provider:?>
Google
Yahoo
Microsoft/Outlook/Hotmail/Live/Office365
//require 'vendor/autoload.php';
require '/home/username/public_html/subdomain/lib/pkp/lib/vendor/autoload.php';
session_start();
$providerName = '';
if (array_key_exists('provider', $_GET)) {
$providerName = $_GET['provider'];
$_SESSION['provider'] = $providerName;
} elseif (array_key_exists('provider', $_SESSION)) {
$providerName = $_SESSION['provider'];
}
if (!in_array($providerName, ['Google', 'Microsoft', 'Yahoo'])) {
exit('Only Google, Microsoft and Yahoo OAuth2 providers are currently supported in this script.');
}
//These details are obtained by setting up an app in the Google developer console,
//or whichever provider you're using.
$clientId = 'my_client_id.apps.googleusercontent.com';
$clientSecret = 'my_client_secret';
//If this automatic URL doesn't work, set it yourself manually to the URL of this script
//$redirectUri = (isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$redirectUri = 'https://subdomain.my_domain_name.com/lib/pkp/lib/vendor/phpmailer/phpmailer/get_oauth_token.php';
$params = [
'clientId' => $clientId,
'clientSecret' => $clientSecret,
'redirectUri' => $redirectUri,
'accessType' => 'offline'
];
$options = [];
$provider = null;
switch ($providerName) {
case 'Google':
$provider = new Google($params);
$options = [
'scope' => [
'https://mail.google.com/'
]
];
break;
case 'Yahoo':
$provider = new Yahoo($params);
break;
case 'Microsoft':
$provider = new Microsoft($params);
$options = [
'scope' => [
'wl.imap',
'wl.offline_access'
]
];
break;
}
if (null === $provider) {
exit('Provider missing');
}
if (!isset($_GET['code'])) {
// If we don't have an authorization code then get one
$authUrl = $provider->getAuthorizationUrl($options);
$_SESSION['oauth2state'] = $provider->getState();
header('Location: ' . $authUrl);
exit;
// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
unset($_SESSION['provider']);
exit('Invalid state');
} else {
unset($_SESSION['provider']);
// Try to get an access token (using the authorization code grant)
$token = $provider->getAccessToken(
'authorization_code',
[
'code' => $_GET['code']
]
);
// Use this to interact with an API on the users behalf
// Use this to get a new access token if the old one expires
echo 'Refresh Token: ', $token->getRefreshToken();
}`
The text was updated successfully, but these errors were encountered: