Search code examples
oauth-2.0

Application to Application access within the same suite of applications


Assume my company is offering 2 applications, say Mail and Calendar. Both applications are using OAuth 2 to secure access.

Now Calendar wants to access data from Mail. If those were applications from two different vendors it would be natural for Calendar to ask the user to authorize it's access to Mail etc.

But since the applications come from the same source I'd like them to be able to share data without the user having to explicitly give permissions.

Or to put it differently: I have ID/Access/Refresh tokens for Calendar. How can I exchange them for an Access Token for Mail without bothering the user?

How can this be done in OAuth 2? I control both the applications and the Identity Provider.

The only solution that comes to my mind is for both Mail and Calendar to be the same Application, but that doesn't seem right (and has other issues, e.g. if you want to restrict someone's access to one of them). I could also implement special access outside of OAuth 2 but that is even worse.

A real world example would be Gmail and Google Calendar. They both present OAuth 2 interface to the outside world, but you don't have to allow them to talk to each other.

PS. References to white papers or cases studies would be appreciated


Solution

  • SEPARATED CLIENTS

    By default in OAuth you would register multiple clients which get their own tokens. You would then use Single Sign On when navigating between them the first time:

    Client ID: app1
    Scope: openid scope1
    Redirect URI: https://app1.mycompany.com
    
    Client ID: app2
    Scope: openid scope2
    Redirect URI: https://app2.mycompany.com
    

    If user consent is involved the user has more choice this way of how they grant access to their personal assets.

    COMBINED CLIENT

    You could potentially combine these into a single entry like this. Note that there is usually a hosting prerequisite of a single base domain in order for token / cookie storage to work:

    Client ID: combinedapp
    Scope: openid scope1 scope2
    Redirect URIs: [https://app1.mycompany.com https://app2.mycompany.com]
    

    PROS AND CONS

    The first option is cleanest most of the time, since you avoid tokens with access to too much data. The second option can make sense for related micro-UIs that are really a single app with the same permissions.

    APIs AND SCOPES

    To share data across apps, companies build API endpoints. You can then have multiple apps that each use scopes representing multiple business areas. See the Scope Best Practices article as a starting point for designing authorization. Eg user logs into calendar app with scopes openid calendar mail - and therefore can get mail data also.