I am trying to integrate SAP cloud with azure Ad for Oauth2.0 setup.

George Geoffrick G 40 Reputation points
2024-12-04T08:59:24.53+00:00

I am trying to integrate SAP cloud with azure Ad for Oauth 2.0 setup.I have created a app in ad with necessary permissions to send email and also provided consent.The SAP user was able to generate token using my cred but after token is generated he is not able to send email using te token . getting error

Below error

com.sap.esb.oauth.token.access.TokenAccessException: Access token request via refresh_token grant type for OAuth2 Authorization Code credential 'SAP_Integration_2' failed after 5 retries: HTTP request failed: {"error":"invalid_grant","error_description":"AADSTS65001: The user or administrator has not consented to use the application with ID '' named 'SAP_Integration_2'. Send an interactive authorization request for this user and resource.

Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
{count} votes

Accepted answer
  1. CarlZhao-MSFT 46,376 Reputation points
    2024-12-05T11:13:43.2+00:00

    Hi @George Geoffrick G

    By analyzing your access token, I found that the logged in user is a guest user, which may be the cause of the problem. As far as I know, sending mail on behalf of a guest user is not currently supported, only on behalf of their identity in their home tenant.

    So, try to configure your app as a multi-tenant app, and then change /{tenant_id} to /common to log in and send mail using their identity in the home tenant.

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


1 additional answer

Sort by: Most helpful
  1. FrankEscarosBuechsel-MSFT 900 Reputation points Microsoft Employee Moderator
    2024-12-16T13:58:12.05+00:00

    Hi @George Geoffrick G,

    Thank you for the offline update. Glad to hear that the issue is now resolved. I'm summarizing the discussion below in an answer for visibility so that other users facing the same problem can find a working solution easier.

    The issue you were facing was indeed based on the tenancy setup in where the app registration and email inbox resided. You created the app registration in tenant A and the mailbox was present in tenant B. The admin consent was given in tenant A, however since the mailbox resided in a different tenant you also needed admin consent in tenant B. Once this was granted sending emails was successful.

    Please don’t forget to close the thread by clicking "Accept the answer" wherever the information provided helps you, as this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.