import { HttpService, SSOApi } from 'authsafe-ts';
const user = await oauthService.getUser();
const httpService = new HttpService(user?.access_token);
const ssoApi = new SSOApi(httpService);await ssoApi.listConnections(): Promise<SSOConnection[]>interface SSOConnection {
id: string;
name: string;
provider: 'saml' | 'google' | 'microsoft' | 'github' | 'custom-oidc';
enabled: boolean;
created_at: string;
metadata?: Record<string, any>;
}const connections = await ssoApi.listConnections();
console.log('SSO providers:', connections);await ssoApi.getConnection(connectionId: string): Promise<SSOConnection>const connection = await ssoApi.getConnection('conn-123');
console.log('Provider:', connection.name, connection.provider);await ssoApi.createConnection(data: {
name: string;
provider: 'saml' | 'google' | 'microsoft' | 'github' | 'custom-oidc';
config: SSOProviderConfig;
}): Promise<SSOConnection>interface SAMLConfig {
entity_id: string;
sign_in_url: string;
certificate: string;
sign_request?: boolean;
signature_algorithm?: 'sha256' | 'sha512';
}interface OIDCConfig {
client_id: string;
client_secret: string;
authorization_endpoint: string;
token_endpoint: string;
userinfo_endpoint?: string;
scope?: string[];
}const connection = await ssoApi.createConnection({
name: 'Okta SSO',
provider: 'saml',
config: {
entity_id: 'https://dev-123.okta.com',
sign_in_url: 'https://dev-123.okta.com/app/sso/saml',
certificate: '-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----',
sign_request: true,
},
});const connection = await ssoApi.createConnection({
name: 'Google Workspace',
provider: 'google',
config: {
client_id: 'your-google-client-id',
client_secret: 'your-google-client-secret',
hd: 'yourcompany.com', // Restrict to domain
},
});await ssoApi.updateConnection(
connectionId: string,
data: Partial<SSOConnection>
): Promise<SSOConnection>const updated = await ssoApi.updateConnection('conn-123', {
enabled: true,
name: 'Updated SSO Name',
});await ssoApi.deleteConnection(connectionId: string): Promise<{ success: boolean }>await ssoApi.deleteConnection('conn-123');
console.log('SSO connection removed');import { OAuthService, HttpService, SSOApi } from 'authsafe-ts';
// Initialize (requires admin token)
const oauthService = new OAuthService({ clientId, redirectUri });
const user = await oauthService.getUser();
const httpService = new HttpService(user?.access_token);
const ssoApi = new SSOApi(httpService);
// Create SAML connection
const samlConnection = await ssoApi.createConnection({
name: 'Corporate SAML',
provider: 'saml',
config: {
entity_id: 'https://idp.example.com',
sign_in_url: 'https://idp.example.com/sso/saml',
certificate: document.getElementById('cert-input').value,
sign_request: true,
signature_algorithm: 'sha256',
},
});
console.log('SAML SSO configured:', samlConnection.id);const googleSSO = await ssoApi.createConnection({
name: 'Google Workspace',
provider: 'google',
config: {
client_id: process.env.GOOGLE_CLIENT_ID,
client_secret: process.env.GOOGLE_CLIENT_SECRET,
hd: 'yourcompany.com', // Domain restriction
scope: ['openid', 'email', 'profile'],
},
});
console.log('Google SSO enabled');// Get all connections
const connections = await ssoApi.listConnections();
// Enable/disable connections
for (const conn of connections) {
if (conn.provider === 'saml') {
await ssoApi.updateConnection(conn.id, { enabled: true });
}
}
// Delete old connections
const oldConnections = connections.filter((c) => !c.enabled);
for (const conn of oldConnections) {
await ssoApi.deleteConnection(conn.id);
}