Hosting & Domaining Forum

Domain Marketplace => Domain Names => Topic started by: lilyalvin on Jan 06, 2023, 01:17 AM

Title: Authorization for different domain names
Post by: lilyalvin on Jan 06, 2023, 01:17 AM
Hey there! The discussion revolves around a forum and a self-made website operating on distinct domains, specifically forum.de (built on cms xenforo) and site.com. The login process on site.com happens via the forum api. The query is regarding the possibility of transferring a session between these domains or finding another alternative. To put it concisely, the objective is for a user to log in on both the platform simultaneously. Since accessing cookies from another domain might not be feasible, I am curious about the authentication system utilized by other websites such as giktimes and toaster.

Title: Re: Authorization for different domains
Post by: AaronJacobson on Jan 06, 2023, 01:42 AM
The problem at hand is the issuance of a token while authenticating, which is then used by the client in their requests. This mechanism closely resembles Google's JSON Web Tokens (JWT).

Title: Re: Authorization for different domains
Post by: kevin66 on Jan 06, 2023, 02:06 AM
It is plausible to only employ one domain for authorization by directing requests towards it. Therefore, when sending requests from the second domain, an alternative session variable needs to be provided to retrieve data from that particular variable. It is essential to keep in mind the allow-origin header while carrying out this procedure.
Title: Re: Authorization for different domain names
Post by: ErichViell on Oct 18, 2023, 01:08 AM
The kind of system you're describing is often known as "single sign-on" (SSO). SSO is a property of access control of multiple related, yet independent, software systems. With this property, a user logs in once and gains access to all systems without being prompted to log in again at each of them.

Specifically in your case, if you want a user logged in on one domain (site.com) to automatically be logged in on another domain (forum.de), you'll need to implement some sort of shared authentication system.

While cookies are domain-specific and can't be read or written across domains for security reasons, there are other ways of achieving cross-domain sessions:

SSO System: You could implement an SSO server which both of your sites contact. When a user logs in on site.com, site.com contacts the SSO server which creates a session. When the user then navigates to forum.de, forum.de also contacts the SSO server, sees that there's a valid session, and logs the user in.

Token-Based System: The login process at site.com (which happens via the forum api) gives back a token that you could pass to forum.de, and have forum.de validate the token against a shared secret or public API.

Third-Party SSO: An alternative is using a third-party single sign-on solution, letting a third-party manage the authentication and then set the authenticated session on both domains.

Regarding Giktimes, Toaster, or any other large websites, many would likely use a similar approach. They would host an authentication server that the main site and any subdomains would use for logins. This shared server can create a universally valid session or token which, once authenticated, can be used by any other services the company operates.

It's important to remember that all of these implementations require proper encryption, best practice security measures, and a strong understanding of auth protocols to ensure secure transfer of information.

Before you start implementing this, I would suggest further studying about topics such as OAuth, JWT (JSON Web Tokens), SSO, and session management over different domains to make sure you're aware of all the potential security risks and know how to handle them effectively.

Please note that as rules and requirements can radically vary according to business needs or specific legal requirements (like GDPR for European Union), it's always advisable to conduct a professional risk assessment and maybe consult with a legal advisor before setting up any large mitigating measures.


Here's a more technical dive into a possible solution:

Single Sign-On System: For an SSO system, the user starts by trying to access one of the protected resources, let's say the site.com. Since the user is not authenticated, site.com redirects the user to the SSO server's login page, passing along a callback URL which the SSO server will redirect the user back to after login.

When the user fills out their login credentials and submits the form, the SSO server checks them and, assuming they are correct, creates an SSO session tied to the user. The SSO server then redirects the user back to the callback URL provided by site.com, this time including a token in the redirect URL.

Site.com takes this token and makes a back-channel request (a server-to-server request) to the SSO server, passing along the token. The SSO server verifies that the token matches the user's session and, if it does, sends back a set of user claims (information about the user) in response.

Site.com now knows that the user is authenticated and creates a local session for the user. If the user then navigates to forum.de, the same flow happens -- they are redirected to the SSO server's login page, but this time, because they already have an SSO session, they are immediately redirected back to forum.de with a token.

Similar to site.com, forum.de also makes a back-channel request to the SSO server and receives the user claims to create a session for the user. In this way, the user only needs to provide their credentials once.

Domain Trusts: Cookies can't be read or written across domains for security reasons, but subdomains can share cookies if the domain attribute is correctly set. If site.com and forum.de were instead site.com and forum.site.com, the same login cookies could be used on both sites.

Third-Party SSO Like OAuth/OpenID: OAuth/OpenID are open standards for token-based authentication and authorization which could be used in place of a custom SSO system. They work similarly to the SSO system described above, but also include additional features like consent screens.

In order to dive deeper, let's consider an in-depth approach on how you can implement Single Sign-On (SSO) using JSON Web Tokens (JWT), one common method for doing cross-domain authentication.

JWT-based SSO process:

User Registration and Login: The user registers or logs in on the main website (eg. site.com). When the user first creates an account or logs in, an authentication server either generates an access token and a refresh token, or sets a secure HTTP-only cookie.

Generating a JWT: The authenticated site.com server generates a JWT token holding a payload of user information. This could include the user ID, username, email address and possibly roles or permissions. The token is signed with a secret key so it can be verified later.

Token Transfer: This JWT token is then transferred to the other desired website (eg. forum.de). This could take place through sending the token as a parameter in the URL but, importantly, the information must be sent securely. An HTTPS connection should be used to ensure that the token cannot be intercepted during transfer.

Verifying JWT at the Secondary Site: Now let's say the user visits forum.de. The server at forum.de would first check to see if a valid JWT already exists (perhaps as a cookie or in local storage). If it does, the user is already authenticated and can proceed. If it does not exist (perhaps this is the user's first visit), forum.de would have to receive this JWT from site.com. Once forum.de receives the JWT, it verifies the credentials using the secret key.

Create Session/Local Storage: Once the JWT is validated, forum.de can create a session for the user or store the user token in local storage (if you're using a single page application). And there you go--the user is now logged into site.com and forum.de simultaneously.

The keys to this operation are:

The security of the JWT secret key. If this key is compromised, anyone could generate their own tokens and gain unauthorized access to the system. The key should be complex and stored securely.

Proper management of token lifespan is also critical. Make sure the JWT tokens expire after a certain amount of time and carefully manage their renewal.

Although local data inside the JWT is encrypted, sensitive data should never be stored inside the payload of a JWT because if someone gets access to the token, they could potentially decode its content.

Remember: each domain should confirm with the originating authentication server that the user's session is still valid, to protect against scenarios when a user signs out or changes their password. This means that the authentication server should have endpoints to revoke the user's JWT tokens or blacklist it.

Disclaimer: Cross-domain authentication is a challenge and any small mistake might open up your system for vulnerabilities. So, always ensure that you are following best-practices and possibly get your system audited by security experts before moving it to a production environment.