barbushin / php-imap

Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)
MIT License
1.67k stars 460 forks source link

[Feature Request] Google OAuth Support #411

Open freescout-helpdesk opened 4 years ago

freescout-helpdesk commented 4 years ago

Is Google OAuth authentication supported in this library? https://github.com/google/gmail-oauth2-tools/issues/18

Sebbo94BY commented 4 years ago

Very good point! Right now, it's not supported yet, unfortunately.

I've added a few functions in order to support OAuth, but I couldn't test it yet. It should later work like this:

// Create PhpImap\Mailbox instance for all further actions
$mailbox = new PhpImap\Mailbox(
    '{imap.gmail.com:993/imap/ssl}INBOX', // IMAP server and mailbox folder
    'some@gmail.com', // Username for the before configured mailbox
    '*********', // Password for the before configured username
    __DIR__, // Directory, where attachments will be saved (optional)
    'UTF-8' // Server encoding (optional)
);

try {
    $mailbox->setOAuthToken('TheOAuthAccessToken');
} catch (Exception $ex) {
    die('Authentication using OAuth failed! Error: '.$ex->getMessage());
}

try {
    $mailsIds = $mailbox->searchMailbox('ALL');
} catch(PhpImap\Exceptions\ConnectionException $ex) {
    die('IMAP connection failed: '.$ex);
}

if(!$mailsIds) {
    die('Mailbox is empty');
}

$mail = $mailbox->getMail($mailsIds[0]);

You can give it a try by using the develop branch: git checkout develop

I'll try to implement a working and tested solution, but this will earliest happen next year due to the current holidays. Any help would be appreciated.


Useful references:

bapcltd-marv commented 4 years ago

running automated testing for this would require changes mentioned in https://github.com/barbushin/php-imap/issues/432#issuecomment-578825685, or finding an IMAP-enabled mail provider that supports automated account creation w/ oauth imap so the account can be created & deleted on each travis build.

hrst commented 3 years ago

Please forgive me asking, but are there any updates on this? It would be so helpful to have OAuth support for e.g. GMail/Google Workspace, and Microsoft Office 365 mail accounts.

I'm willing to help / do the implementation, what is the current status?

Sebbo94BY commented 3 years ago

There are no updates yet.

I've tried to work and implement it some time ago, so the current progress is available in the respective branch: 411-OAuth-Support

Feel free to submit your own pull request or add commits to the existing one.

francescobianco commented 2 years ago

Hi! @freescout-helpdesk @Sebi94nbg @hrst @bapcltd-marv @rmontagud

The strategy to overcome the problem is replacing all the imap_* functions with the equivalent imap2_*

etc...

The idea behind the imap2 library is to replace the core php imap extension with a new one written in PHP. Why? We have problem with the UW-IMAP https://github.com/uw-imap/imap it seem outdate from 2019. There are many security concerns about it

I'm waiting from your feedback! I hope that imap2 is a good replacement for imap

cc @millnet-maho

hrst commented 2 years ago

Just a heads-up to everyone: Microsoft will disable Basic Auth on Oct 1st, 2022. In contrast to Google, "App Passwords" will not be possible/allowed, only OAuth2.

Status for PHP imap_* extension (page not updated since 2020 as of writing this): https://wiki.php.net/todo/ext/imap/xoauth2

bhanu2217 commented 2 years ago

When we plan to add support for oAuth to this package?

kurznet commented 2 years ago

is there any plan to support oAuth? because Microsoft will disable Basic Auth in Januar 2023 look here: https://techcommunity.microsoft.com/t5/exchange-team-blog/basic-authentication-deprecation-in-exchange-online-september/ba-p/3609437

nettunodev commented 2 years ago

Hello, as a workaround is there maybe the possibility to login using another library, like https://www.php-imap.com/ that does support oauth and then pass the object in some way to keep working with this php-imap library? We built a whole app using this library and we would do anything to avoid rewriting everything... Thanks!

Sebbo94BY commented 1 year ago

Hello everyone, back in 2019 I already worked on the OAuth support, but I had no chance to test it.

These changes are still on the 411-OAuth-Support branch, so if somebody could test it and provide feedback, it would be great.

Pull requests by other people are also welcome.

Since christmas time is coming soon and I'm also currently working on some other projects, I can't gurantee, that I can finish this implementation until end of December 2022. However, I'll try my best to get it done.

VortexCallouts commented 1 year ago

has anyone be able to get this to work correctly I am trying to update for Outlook update.

kurznet commented 1 year ago

hi everyone, any news about OAuth-Support? we got today the "Exchange Online Basic Auth Deprecation – 7 Day Notice" in Office 365 Center

Approximately 7 days from today, we’re going to permanently disable basic authentication for the following Exchange Online protocols: MAPI, RPC, Offline Address Book, Exchange Web Services, POP, IMAP, Exchange ActiveSync and Remote PowerShell.

within the next 7 days basic auth will be deactivated, so we need a solution soon....

francescobianco commented 1 year ago

@barbushin any plan to manage OAUTH?

PauchardThomas commented 1 year ago

Same here