Skip to content

Added auth plugin for Xoauth2#227

Merged
Slamdunk merged 10 commits intolaminas:2.22.xfrom
EmeryEx:2.22.x
Jan 18, 2023
Merged

Added auth plugin for Xoauth2#227
Slamdunk merged 10 commits intolaminas:2.22.xfrom
EmeryEx:2.22.x

Conversation

@EmeryEx
Copy link
Copy Markdown
Contributor

@EmeryEx EmeryEx commented Jan 10, 2023

  • Are you adding something the library currently does not support?
    Yes
  • Why should it be added?
    So you can connect to services like Microsoft Office 365 and utilize SMTP that doesn't support legacy protocols
  • What will it enable?
    Xoauth2 auth protocol for SMTP
  • How will the code be used?
    via the Laminas\Mail\Protocol\SmtpPluginManager as "xoauth2" or by "connection_class" option as "xoauth2" on SmtpOptions fed into SmtpTransport in a factory

I'm sorry i don't see a develop branch. I'm new to this.

Signed-off-by: Emery <emery@shopjimmy.com>
Signed-off-by: Emery <emery@shopjimmy.com>
Signed-off-by: Emery <emery@shopjimmy.com>
Signed-off-by: Emery <emery@shopjimmy.com>
@EmeryEx
Copy link
Copy Markdown
Contributor Author

EmeryEx commented Jan 10, 2023

This was a copy of AUTH PLAIN. Some of the checks are not passing for code that is already in the framework in same fashion in another file, but i've tried this on local and it works.

Copy link
Copy Markdown
Contributor

@Slamdunk Slamdunk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the Psalm errors are shared among all Auth classes, and you just copy-pasted most of the code.

I'm fine with this, but please update the psalm baseline to get the CI green

Comment thread src/Protocol/Smtp/Auth/Xoauth2.php Outdated
Comment thread src/Protocol/Smtp/Auth/Xoauth2.php Outdated
EmeryEx and others added 6 commits January 11, 2023 20:29
Co-authored-by: Filippo Tessarotto <zoeslam@gmail.com>
Signed-off-by: Emery <emery@shopjimmy.com>
Co-authored-by: Filippo Tessarotto <zoeslam@gmail.com>
Signed-off-by: Emery <emery@shopjimmy.com>
Signed-off-by: Emery <emery@shopjimmy.com>
Signed-off-by: Emery <emery@shopjimmy.com>
Signed-off-by: Emery <emery@shopjimmy.com>
Sorry about all that

Signed-off-by: Emery <emery@shopjimmy.com>
@EmeryEx EmeryEx mentioned this pull request Jan 12, 2023
@Slamdunk Slamdunk added this to the 2.22.0 milestone Jan 18, 2023
@Slamdunk Slamdunk merged commit 1d307ff into laminas:2.22.x Jan 18, 2023
@Slamdunk
Copy link
Copy Markdown
Contributor

Thank you @EmeryEx

@froschdesign
Copy link
Copy Markdown
Member

@EmeryEx @Slamdunk
There is a simple rule: what is not documented does not exist!
How can developers discover this and use it without documentation?

It would be a pity if the work invested here is not used!

@Slamdunk
Copy link
Copy Markdown
Contributor

My bad, sorry.

@EmeryEx would you be so kind to update https://github.com/laminas/laminas-mail/blob/2.22.x/docs/book/transport/smtp-authentication.md as well?

@EmeryEx
Copy link
Copy Markdown
Contributor Author

EmeryEx commented Jan 19, 2023

Yes I will add doc section in the next week or so when I get some time. Thank you guys!

@liowalter
Copy link
Copy Markdown

Thanks for this @EmeryEx. Could you explain how to use it ? Where do I get the access token ?

@EmeryEx
Copy link
Copy Markdown
Contributor Author

EmeryEx commented Mar 8, 2023

Thanks for this @EmeryEx. Could you explain how to use it ? Where do I get the access token ?

It's no easy task and unfortunately, it's something you need to implement yourself. But once you have the access token with the right permissions, you just have to supply it to SmtpTransport:

$transport = new SmtpTransport();

$connection_conf = [
    'username' => $username, // the email address of user that approved token
    'access_token' => $token, // the access token you've acquired via an authorization token or refresh token reuest
    'ssl' => 'tls',
];

$options   = new SmtpOptions([
    'name'              => 'example.com',
    'host'              => 'smtp.office365.com',
    'port'              => 587,
    'connection_class'  => 'Xoauth2',
    'connection_config' => $connection_conf,
]);
        
$transport->setOptions($options);

Then your transport is ready to send mail.

Here are the docs for Office365 on obtaining Access tokens and such:
Docs

One more thing after you've acquired an access token, you still need to enable SMTP auth for the email account as an admin (one time)
Enable SMTP authentication for Office 365 account

@froschdesign
Copy link
Copy Markdown
Member

@EmeryEx
Please create a pull request for it to update the documentation.

@EmeryEx
Copy link
Copy Markdown
Contributor Author

EmeryEx commented Mar 8, 2023

@EmeryEx Please create a pull request for it to update the documentation.

Where exactly should i put it? Not sure the docs flow you've got going on

@froschdesign
Copy link
Copy Markdown
Member

@EmeryEx
In the documentation you will find a chapter "SMTP authentication", add it there.
The related file can be found in the docs folder of this repository:

https://github.com/laminas/laminas-mail/blob/2.22.x/docs/book/transport/smtp-authentication.md

artemii-karkusha pushed a commit to artemii-karkusha/laminas-mail that referenced this pull request May 24, 2023
Added auth plugin for Xoauth2
@YalagureshJ
Copy link
Copy Markdown

Hi @EmeryEx, Is this working? Please share the documentation on how to use it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants