Skip to content

Fixes Microsoft 365 OAUTH2 authentication workflow no longer works #9598#9939

Open
lambjs wants to merge 2 commits intoroundcube:masterfrom
lambjs:fix/9598-m365-oauth-fix
Open

Fixes Microsoft 365 OAUTH2 authentication workflow no longer works #9598#9939
lambjs wants to merge 2 commits intoroundcube:masterfrom
lambjs:fix/9598-m365-oauth-fix

Conversation

@lambjs
Copy link

@lambjs lambjs commented Jul 24, 2025

See:
Microsoft 365 OAUTH2 authentication workflow no longer works
#9598

Modfiy rcmail_oauth.php and config defaults and examples to allow changing of scope for identity API calls. This is required after Microsoft has changed their API's such that the scopes used for regular mailbox interactions are incompatible with those used for identity operations.

…e when fetching identity information. Fixes M365 oauth login. Refs roundcube#9598
@alecpl
Copy link
Member

alecpl commented Jul 26, 2025

Couldn't that be implemented with a single extra request instead of two?

@Neustradamus
Copy link

@alecpl: I will be fixed in 1.7?

@lambjs
Copy link
Author

lambjs commented Jul 31, 2025

Couldn't that be implemented with a single extra request instead of two?

@alecpl:

I think you're right. I had assumed that using the current token to do a refresh would invalidate the current token data and require another refresh to get another working token with the correct scope for regular mailbox operations. After changing the naming so I didn't overwrite the pre-existing auth data, and removing the second call to refresh_access_token, my tests seem to succeed. I've pushed another change, please take a look and let me know if okay to merge?

$authorization_ident = $refresh_response['authorization'];
}

$fetched_identity = $this->fetch_userinfo($authorization_ident);
Copy link
Member

Choose a reason for hiding this comment

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

$authorization_ident does not exist if $this->options['scope_identity'] is unset.

// request user identity (email)
if (empty($username)) {
$fetched_identity = $this->fetch_userinfo($authorization);
if($this->options['scope_identity']) {
Copy link
Member

Choose a reason for hiding this comment

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

Add a space after if, please.

'client_secret' => $oauth_client_secret,
];

if($change_scope) {
Copy link
Member

Choose a reason for hiding this comment

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

Add space after if, please. And rename $change_scope to $scope.

@alecpl
Copy link
Member

alecpl commented Oct 5, 2025

@lambjs would you mind finishing this, please? We're getting close to the 1.7-rc release. It would be nice to include this.

@Neustradamus
Copy link

@lambjs: Please look your PR, it will be nice to have in 1.7...

Thanks in advance.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants