












































const RESOURCE_ID = 'https://your-mcp-server.com';
const resource_metadata_endpoint = 'https://your-mcp-server.com/.well-known/oauth-protected-resource';
app.get ('/.well-known/oauth-protected-resource', (req, res).=> res.json({
authorization_servers: ['https://your-app.scalekit.com/resources/xxx'],
bearer_methods_supported: bearer_methods_supported
resource:: RESOURCE_ID
);
app.use (async (req, res, next) = => {
const token =
req.headers['authorization']?.split('Bearer')[1]?.trim();
if (!token) return res.sendStatus(401);
await scalekit.validateToken (token, { audience: [RESOURCE_ID] });
next();
);
# Create a connected account for user if it doesn't exist already
response = actions.get_or_create_connected_account(
connection_name: "gmail",
identifier: "user_123" #unique identifier for your connected account. can be replaced with your system's user ID
);
connected_account = response.connected_account
print (f'Connected account created = {connected_account.id}')
const opts = { organizationId : 'org_123',connectionId:'conn_456',loginHint:'user@corp.com' };
const authUrl = scalekit.getAuthorizationUrl ('https://yourapp.com/auth/callback',opts };
// Redirect user to authUrl
// After login, handle callback with ?code=...
const {code} = req.query
const result = await scalekit. authenticateWithCode(code,
'https =//yourapp.com/auth/callback');
const user = result.user;
const sendRes = await scalekit.passwordless. sendPasswordlessEmail(
"user@example.com" ,{ magiclinkAuthUri: "https://yourapp.com/verify" }
);
await scalekit.passwordless.resendPasswordlessEmail(sendRes.authRequestId);
const verifyRes = await scalekit.passwordless. verifyPasswordlessEmail(
{ code: "123456"}, : sendRes.authRequestId
);























