How was access granted exactly?
They should be following this model:
https://learn.microsoft.com/en-us/exchange/permissions-exo/application-rbac
or the older architecture:
https://learn.microsoft.com/en-us/graph/auth-limit-mailbox-access
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I’m developing an application that checks emails in a shared mailbox and moves them to different folders based on certain variables. So far, I’ve managed to do this using delegated access, logging in through a browser with my account. However, since I want to run it on a server, I need it to work without user authentication each time.
Everything works correctly with delegated access, and I can move emails in both my account and the shared mailbox. However, after switching to app authentication, I get the following error:
APIError Code: 403 Message: None Error: MainError(code='ErrorAccessDenied', message='Access is denied. Check credentials and try again.')
The Microsoft Entra admin granted full permissions to this application, which is why it works with delegated access. What could be causing this issue?
My code:
scopes = ['https://graph.microsoft.com/.default']
client = GraphServiceClient(credential, scopes=scopes)
query_params = MessagesRequestBuilder.MessagesRequestBuilderGetQueryParameters(
select=['from', 'isRead', 'receivedDateTime', 'subject'],
top=25,
orderby=['receivedDateTime DESC']
)
request_config = MessagesRequestBuilder.MessagesRequestBuilderGetRequestConfiguration(
query_parameters=query_params
)
#
messages = await client.users.by_user_id('******@majorel.com').messages.get(
request_configuration=request_config
)
Thank you.
How was access granted exactly?
They should be following this model:
https://learn.microsoft.com/en-us/exchange/permissions-exo/application-rbac
or the older architecture:
https://learn.microsoft.com/en-us/graph/auth-limit-mailbox-access
Make sure you have assigned one of the following application permissions to the calling app and granted admin consent for the permissions.
Export your access tokens and decode using jwt.ms and you should be able to see them in the roles
claim.
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.