.NET Example of Creating a
vSphere Automation
API Session with a SAML Token

This example is based on code in the
ExternalPscSsoWorkflow.cs
sample file.
This example uses the steps that are described in the Create a vSphere Automation Session with a SAML Token
For a complete and up-to-date version of the sample code, see the vSphere Automation SDK .NET samples at GitHub.
... StubFactory = CreateApiStubFactory(server); // Create a SAML security context using SAML bearer token ExecutionContext.SecurityContext samlSecurityContext = new SamlTokenSecurityContext( samlBearerToken, null); /* * Create a stub configuration with saml security * context */ StubConfiguration stubConfig = new StubConfiguration(); stubConfig.SetSecurityContext(samlSecurityContext); // Create a session stub using the stub configuration. Session session = StubFactory.CreateStub<Session>(stubConfig); // Log in and create a session char[] sessionId = session.Create(); /* * Initialize a session security context from the generated * session id */ SessionSecurityContext sessionSecurityContext = new SessionSecurityContext(sessionId); // Update the stub configuration to use the session id stubConfig.SetSecurityContext(sessionSecurityContext); /* * Create a stub for the session service using the authenticated * session */ this.sessionSvc = StubFactory.CreateStub<Session>(stubConfig); VM vmService = StubFactory.CreateStub<VM>(stubConfig);