Reputation: 1741
I am trying to figure out the best way to implement cross domain authentication.
Scenario:
As a user I log in to youtube.com, when I visit Google.com by typing the domain name https://www.google.com in a new browser tab, my session is preserved.
Problem:
As a developer, how do I implement the cross domain authentication in away that is secure, future proof and user friendly?
I will use the example of Google and YouTube to explain the problem. The parties that will be evolved in this examples are:
Possible solution 1
Use the SameSite attribute to create a Third-Party Cookie
that will be used for authentication. This cookie will be used to store and maintain the user's session cross the websites.
Example
Pros:
Cons:
As of 2022 such cookies are blocked on most browsers:
1.1 The usage of Third-Party Cookies is blocked in Safari since version 13.1.
1.2 This year Firefox introduced Total Cookie Protection, which “ensures that no cookies can be used to track you from site to site as you browse the web.”
1.3 Google is planning to phase out third party Cookies by 2023 and replace them with FLoC.
Possible solution 2
Pros:
Cons:
Questions
Upvotes: 8
Views: 3802
Reputation: 29273
SOLUTION 1
Cross domain solutions have blocking issues as you have articulated. These days you need to design hosting domain names to share a base domain such as *.example.com
if you want to share (first party) cookies.
An example is how in Google you can navigate between drive
, mail
and calendar
without redirects, because all 3 apps are hosted in the same parent domain. Note that the resources involved are quite similar.
SOLUTION 2
This is the OAuth standard way of doing things. The Identity Provider cookie is third party but not (currently) dropped in any browser when there is a top level redirect in the browser, since this acts as a user gesture.
The redirect per app results in each app getting its own tokens and lifetimes with permissions specific to that app, which is cleaner from a security viewpoint.
WHICH OPTION?
I might choose option 1 for a Micro UI based architecture, where a single app is deployed as three technical conponents, or for a small set of apps with essentially the same privileges.
Option 2 is simpler to manage as software scales, and some apps have higher privileges than others. It will fare better if you have to explain your security to customers or undergo PEN tests.
I think single sign out options may be better in solution 1. It is usually seen as a secondary requirement though, and these days people understand that this is an area with technology limitations.
Upvotes: 2