Perl Example of
Creating a
vSphere
Automation API Session with a SAML Token
vSphere
Automation
API Session with a SAML TokenThis example is
based on the code in the
external_psc_sso_workflow.pl
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 Perl
samples at GitHub.
... # 1 - Create a stub configuration. $my_stub_config = new Com::Vmware::Vapi::Bindings::StubConfiguration(); # 2 - Create a SAML token security context. my $context_factory = new Com::Vmware::Vapi::Dsig::SecurityContextFactory(); my $saml_token_context = $context_factory->create_saml_security_context( 'token' => $my_saml_token, 'private_key' => $my_private_key); # 3 - Apply the token security context to the stub configuration. $my_stub_config->set_security_context( security_context => $saml_token_context); # 4 - Create a session stub, using the token security context. my $protocol_factory = new Com::Vmware::Vapi::Protocol::ProtocolConnectionFactory(); $my_connection = $protocol_factory->get_connection( 'protocol_type' => 'https', 'uri' => "$my_vapi_url/api"); $my_stub_factory = new Com::Vmware::Vapi::Bindings::StubFactory( 'api_provider' => $my_connection->get_api_provider() ); $my_vapi_stub = $my_stub_factory->create_stub( 'service_name' => 'Com::Vmware::Cis::Session', 'stub_config' => $my_stub_config); # 5 - Use the create() operation to create an authenticated session. my $session_id = $my_vapi_stub->create(); # 6 - Create a session security context and update the stub configuration # to use the session ID. my $session_id_context = $context_factory->create_session_security_context( 'session_id' => $session_id); $my_stub_config.set_security_context( security_context => $session_id_context); # 7 - Create a new session stub, using the session security context. $my_vapi_stub = $my_stub_factory->create_stub( 'service_name' => 'Com::Vmware::Cis::Session', 'stub_config' => $my_stub_config);