-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid_grant AADSTS9002313: Invalid request.Request is malformed or invalid #114
Comments
Original: thephpleague/oauth2-client#850 Could you please post a sample code which you are using to obtain the token and the version of oauth2-azure which you are using? /cc: @decomplexity |
Tnx Jan.
|
So couple questions... Why are you using SMTP sending instead of Microsoft Graph - which is more preferred way of sending mail? I would suggest to rely on I noticed that you have the |
Tnx Jan.
Background Hence our tests to see if a straightforward authentication change to PHPMailer were possible, leaving all the PHPMailer header, To/Ccc/Bcc, AddUser etc etc stuff intact. The trial of amending PHPMailer to support Oauth2 were partly driven by the need for better security but mainly by MSFT deprecating SMTP AUTH Basic Authentication with its cessation planned for Q3'ish 2021. And a MSFT bombshell post a few days ago states that new tenants will be blocked by default from SMTP AUTH using both Basic Authentication AND Oauth2, – i.e. they will block it at the protocol level. Although this block can be unset using Powershell, it will cause lots of “it has just stopped working” problems for those who don’t realise what has happened. The StevenMaguire provider for PHPMailer that has been used for several years for Hotmail, Windows Live Mail and similar is failing with V2 endpoints, and MSFT say that V2 is a prerequisite for SMTP AUTH with Oauth2. Hence our trial of your Azure provider. |
Yes, I am aware of the SMTP not supporting client_credentials, that was mostly aimed at Microsoft Graph usage. The refresh token should be the full refresh token, you should never make changes to it, since it will break the token. State and session_state don't need to be included. If you were to use MS Graph, you could use client_credentials. But let's focus on this to work with SMTP:
$provider->pathAuthorize = "/oauth2/v2.0/authorize";
$provider->pathToken = "/oauth2/v2.0/token"; and I would suggest also this one: $provider->tenant = "<tenant-id>"; // Either the GUID or one of your domains. Also, the provider for requesting the token should have same parameters as the one used with phpmailer. I will try to make a demo for you over the weekend (I won't be able to do it sooner, sorry) if we don't managed to figure it out correctly. |
Also, I just noticed... You are doing $provider->defaultEndPointVersion = TheNetworg\OAuth2\Client\Provider\Azure::ENDPOINT_VERSION_2_0; which is not supported with v1.4.2 but Since in dev-master there were some breaking changes, it is rather a v2 candidate not to break everyone's code. Please check the v1.4.2 docs - which are relevant for you if you are using v1.4.2 - https://github.com/TheNetworg/oauth2-azure/tree/v1.4.2 |
Could quite possibly be the cause, with the V1 auth endpoint not recognising a V2 refresh token. |
I have rebuilt using But Invalid_Grant AADSTS9002313: Invalid request is still being flagged up. |
Jan - you asked for the contents of my get_oauth_token. VERSION A
VERSION B
|
This just looks like misconfiguration. I will try to make a sample for you. |
[Shadow post]
I am trying to get PHPMailer to authenticate with SMTP AUTH. I am using the thephpleague’s OAuth2 and thenetworg’s Azure provider via MSFT’s V2 authorisation and token endpoints.
I receive the Invalid Grant error (above).
To avoid double-posting, more detail is the thephpleague’s OAuth2 Issues #850
https://github.com/thephpleague/oauth2-client/issues/new
The text was updated successfully, but these errors were encountered: