Understanding authMiddleware and samlMiddleware in SAML SP Authentication
In our Go SAML SP setup, we have two middlewares that handle authentication:
samlMiddleware(fromsamlsp.New) → Handles SAML authentication, session management, and IdP interactions.authMiddleware(custom middleware) → Stores and restores the original request before authentication.
1️⃣ samlMiddleware – Handles SAML Authentication
This middleware is created using:
✅ What it does:
- Redirects users to the IdP if not authenticated.
- Validates SAML assertions after login.
- Stores user session (e.g., NameID, attributes).
- Provides an endpoint
/saml/to handle SAML requests & responses.
🔹 How it works in routing:
2️⃣ authMiddleware – Stores and Restores Original Request
This is a custom middleware that:
- Saves the original request URL before redirecting to the IdP.
- Passes control to
samlMiddlewarefor authentication. - After successful login, redirects the user back to the stored URL.
✅ Code:
🔹 What it does step-by-step:
- Intercepts the request before authentication.
- Stores the original request URL (so we can return after login).
- Passes the request to
samlMiddleware.RequireAccount, which:- Redirects to the IdP if the user is not authenticated.
- Lets the request pass if the user is authenticated.
- After successful authentication, redirects back to the original request.
🔹 How it works in routing:
No comments:
Post a Comment