Learn how to securely implement IdP-initiated Single Sign-On for your application
This guide shows you how to securely implement Identity Provider (IdP)-initiated Single Sign-On for your application. When users log into your application directly from their identity provider’s portal, Scalekit converts the IdP-initiated request to a Service Provider (SP)-initiated flow for enhanced security.
Review the authentication sequence
The workflow converts the traditional IdP-initiated flow to a secure SP-initiated flow by:
The user logs into their identity provider portal and selects your application
The identity provider sends user details as assertions to Scalekit
Scalekit redirects to your initiate login endpoint with a JWT token
Your application validates the JWT and generates a new SP-initiated authorization URL
To securely implement IdP-initiated SSO, follow these steps to convert incoming IdP-initiated requests to SP-initiated flows:
Set up an initiate login endpoint and register it in Dashboard > Developers > Redirect URLs > Initiate Login URL
Extract information from the JWT token containing organization, connection, and user details
Convert to SP-initiated flow using the extracted parameters to generate a new authorization URL
Handle errors with proper callback processing and error handling best practices
Use the extracted parameters to initiate a new SSO request. This converts the IdP-initiated flow to a secure SP-initiated flow. Here are implementation examples:
If errors occur, the redirect URI will receive a callback with this format:
Terminal window
https://{your-subdomain}.scalekit.dev/callback
?error="<error_category>"
&error_description="<details>"
After completing the SP-initiated flow, users are redirected back to your callback URL where you can complete the authentication process. Next, let’s look at how to test your IdP-initiated SSO implementation.
If your application uses a third-party service like Firebase Authentication to manage user sessions, you must initiate its sign-in flow after completing Step 3.
This process has two stages: first, the IdP redirects the user to your app via Scalekit, and second, your app triggers a new sign-in flow with Firebase using the Authorization URL you just generated.
Review the downstream auth flowDownstream Auth Provider IntegrationUserIdPScalekitYourAppFirebaseSelect your applicationSend IdP requestRedirect with JWTtriggers sign-inuses Authorization URL from Step 3Standard SP-initiated flowSend responseExchange code for tokensUser authenticatedComplete login
The example below shows how to pass the Authorization URL to the Firebase Web SDK.
While IdP-initiated SSO offers convenience, it comes with significant security risks. Scalekit’s approach converts the flow to SP-initiated to mitigate these vulnerabilities.
Stolen SAML assertions: Attackers can steal SAML assertions and use them to gain unauthorized access. If an attacker manages to steal these assertions, they can:
Inject them into another service provider, gaining access to that user’s account
Inject them back into your application with altered assertions, potentially elevating their privileges
With a stolen SAML assertion, an attacker can gain access to your application as the compromised user, bypassing the usual authentication process.
The chief problem with stolen assertions is that everything appears legitimate to the service provider (your application). The message and assertion are valid, issued by the expected identity provider, and signed with the expected key. However, the service provider cannot verify whether the assertions are stolen or not.
If you encounter issues implementing IdP-initiated SSO:
Verify configuration: Ensure your redirect URI is properly configured in Dashboard > Developers > Redirect URLs
Check JWT processing: Verify you’re correctly processing the JWT token from the idp_initiated_login parameter
Validate error handling: Ensure your error handling properly captures and processes any error messages
Test connections: Confirm the organization and connection IDs in the JWT are valid and active
Review logs: Check both your application logs and Scalekit dashboard logs for debugging information