I was reading a blog in angular (https://blog.angular-university.io/angular-jwt-authentication/)from its official website wherein for authentication a separate server is used and for application different server is used. So, in this case cookie will be issued by authentication server but will be used in application server. How is that possible? I am not able to understand the below explanation from that blog:
Cookies and Third-Party Authentication providers
A potential problem with receiving the session JWT in a cookie is that we would not be able to receive it from a third-party web domain, that handles the authentication logic.
This is because an application running on
app.example.com
cannot access cookies from another domain likesecurity-provider.com
.So in that scenario, we would not be able to access the cookie containing the JWT, and send it to our server for validation, making the use of cookies unfeasible.
Can we get the best of the two solutions?
Third-party authentication providers might allow us to run the externally hosted login page in a configurable subdomain of our website, such as for example
login.example.com
.So it would be possible to get the best of all these solutions combined. Here is what the solution would look like:
- an externally hosted login page running on our own subdomain login.example.com, and an application running on example.com
- that page sets an HTTP Only and Secure Cookie containing the JWT, giving us good protection against many types of XSS attacks that rely on stealing user identity
- Plus we need to add some XSRF defenses, but there are well-understood solutions for that.
Someone please explain the below line:
Third-party authentication providers might allow us to run the externally hosted login page in a configurable subdomain of our website, such as for example login.example.com.
What does this mean and how can we implement this on authentication server and how can we access the cookie issued by authentication server in application server. Please clarify if it means setting the domain field as application server in cookie issued by authentication server, or it is something else.
Set-Cookie: <cookie-name>=<cookie-value>; Domain=<domain-value>; Secure; HttpOnly
Also, if this is the case how an application server validates the cookie provided by authentication server. Does authentication server also send this cookie to application server? Do we also have to put that mechanism in place?