SMTP.Send Consent Flow with Daemon Service – Handling Token Refresh

Ranjith Kumar Sekar 0 Reputation points
2025-09-02T09:20:16.08+00:00
  • We are building a feature where users provide consent for the SMTP.Send scope by signing in once through our frontend portal (Angular 19 with MSAL integration).
    • During login, consent for SMTP.Send is granted.
    • The resulting tokens are securely passed to our backend API (built in .NET Framework 4.6.1) and stored.
    • A daemon service then sends scheduled reports as email using the signed-in user’s identity.
    • The daemon should not require further user interaction and must be able to refresh the token automatically.
    Question:
    • What is the Microsoft-recommended approach to implement this flow?
    • Can we use the refresh token with offline_access for this, or is the on-behalf-of flow recommended?
Microsoft 365 and Office | Development | Microsoft 365 App Publishing
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Gabriel-N 9,955 Reputation points Microsoft External Staff Moderator
    2025-09-02T12:23:06.9533333+00:00

    Hi Ranjith Kumar Sekar

    Thank you for reaching out to the Q&A forum.

    While I am not a subject matter expert in this area, I have conducted research to provide you with the most accurate guidance possible. Based on your scenario, I recommend implementing the OAuth 2.0 On-Behalf-Of (OBO) flow. This approach is particularly suited for cases where:

    • A Single Page Application (SPA), such as Angular, manages user authentication and consent.
    • The SPA then delegates control to a secure backend service that calls downstream APIs, such as Microsoft Graph.

    The OBO flow offers the following advantages:

    • It preserves the user’s identity and delegated permissions throughout the request chain.
    • The backend receives only the scopes explicitly consented to by the user, mitigating the risk of privilege escalation.
    • It enables secure service-to-service communication while maintaining the user principal, which is essential for operations such as sending emails on behalf of the user.

    Conversely, the direct approach, where the frontend requests Graph scopes (e.g., Mail.Send, offline_access) and transmits access or refresh tokens to the backend, is not recommended due to:

    • Increased token exposure risk
    • Potential compliance violations
    • Architectural misalignment

    For comprehensive details, please refer to the official Microsoft documentation: Microsoft identity platform and OAuth 2.0 On-Behalf-Of flow

    I hope this information proves helpful.


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

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

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