Skip to content
Talk to an Engineer Dashboard

Bring Your Own Auth

Using Scalekit as a drop-in OAuth 2.1 authorization layer for your MCP Servers with federated authentication to your existing auth layer.

This document explains how to integrate your existing authentication system with Scalekit’s drop-in OAuth 2.1 authorization layer. Follow the steps below to enable seamless and secure OAuth2.1 MCP layer for your users.


Scalekit also offers the option to integrate your existing authentication infrastructure with Scalekit’s OAuth layer for MCP servers. Use this when you have an existing auth system and want to add MCP OAuth without migrating users.

Why use this integration?

When your B2B application already has an established authentication system, you can connect it to your MCP server through Scalekit. This ensures that:

  • Users see the same familiar login screen whether accessing your application or your MCP server
  • No user migration required - your existing user accounts work immediately with MCP
  • You maintain control over your authentication logic while gaining MCP OAuth 2.1 compliance

This “bring your own auth” approach standardizes the authorization layer without requiring you to rebuild your existing authentication infrastructure from scratch.

Important Note: The following changes will need to be made in your B2B apps’s Login API Endpoint. The connection ID, User POST URL and Redirect URI allows your app to know that scalekit is attempting to perform the Token Exchange for MCP Auth, so the user should get redirected to the correct consent screen post MCP Login instead of your B2B app.

When an MCP client initiates an authentication flow, Scalekit redirects to your login endpoint. You then provide user details to Scalekit via a secure backend call, and finally redirect back to Scalekit to complete the process.

Scalekit MCP Bring you own Auth flowMCP ClientScalekit Auth ServerYour B2B App Initiate /oauth/authorize (DCR, CIMD) Redirect to /login?login_request_id&state POST user details (Machine-to-Machine) 200 Success Response (Upon Successful Login) Redirect to /partner:callback?state Continue Consent, token exchange and permissions delegation.
  • The MCP client starts the authentication flow by calling /oauth/authorize on Scalekit.
  • Scalekit redirects the user to your login endpoint, passing two parameters:
    • login_request_id: Unique identifier for the login request.
    • state: Value to maintain state between requests.

Example Redirect URL:

https://app.example.com/login?login_request_id=lri_86659065219908156&state=HntJ_ENB6y161i9_P1yzuZVv2SSTfD3aZH-Tej0_Y33_Fk8Z3g

2. Handle Authentication in Your Application

Section titled “2. Handle Authentication in Your Application”

Once the user lands on your login page:

Take the user through your regular authentication logic (e.g., username/password, SSO, etc.).

Send the authenticated user’s profile details from your backend to Scalekit to complete the login handshake.

Terminal window
pip install scalekit-sdk-python
send_user_details.py
from scalekit import ScalekitClient
import os
scalekit = ScalekitClient(
os.environ.get('SCALEKIT_ENVIRONMENT_URL'),
os.environ.get('SCALEKIT_CLIENT_ID'),
os.environ.get('SCALEKIT_CLIENT_SECRET')
)
# Update login user details
scalekit.auth.update_login_user_details(
connection_id="{{connection_id}}",
login_request_id="{{login_request_id}}",
user={
"sub": "1234567890",
"email": "alice@example.com"
},
)

  • Once you receive a successful response from Scalekit, redirect the user back to Scalekit using the provided state value to the below endpoint.

Example Redirect URL:

{{envurl}}/sso/v1/connections/{{connection_id}}/partner:callback?state={{state_value}}

state_value should match the state parameter you received in Step 1.


  • After processing the callback from your auth system, Scalekit will handle the remaining steps (showing the consent screen to the user, token exchange, etc.) automatically.

Download our sample MCP Server: We have put together a simple MCP server that you can check out and run it locally to test the end to end functionality of a working MCP server complete with authentication and authorization. You can download and execute a sample MCP server implementation from GitHub.