Example #1
0
        static void Main(string[] args)
        {
            // Retrieve the authentication policy for the Discovery service.
            OnlineAuthenticationPolicy discoveryPolicy =
                 new OnlineAuthenticationPolicy(DiscoveryServiceUrl + WsdlSuffix);
            // Authenticate the user using the authentication policy.
            SecurityToken discoveryToken = Authenticate(discoveryPolicy, UserName, UserPassword);

            // Retrieve the organization service URL for the given organization
            string organizationServiceUrl = DiscoverOrganizationUrl(discoveryToken, OrganizationUniqueName, DiscoveryServiceUrl,
                discoveryPolicy.IssuerUri);

            // The Discovery Service token cannot be reused against the Organization Service as the Issuer and AppliesTo may differ between
            // the discovery and organization services.
            OnlineAuthenticationPolicy organizationPolicy =
                new OnlineAuthenticationPolicy(organizationServiceUrl + WsdlSuffix);
            SecurityToken organizationToken = Authenticate(organizationPolicy, UserName, UserPassword);

            // Execute the sample
            ExecuteWhoAmI(organizationToken, organizationServiceUrl, organizationPolicy.IssuerUri);

            Console.Write("Press [Enter] to exit.... ");
            Console.ReadLine();
        }
Example #2
0
        private static SecurityToken Authenticate(OnlineAuthenticationPolicy policy, string userName, string password)
        {
            ClientCredentials credentials = new ClientCredentials();
            credentials.UserName.UserName = userName;
            credentials.UserName.Password = password;

            return WsdlTokenManager.Authenticate(credentials, policy.AppliesTo, policy.Policy, policy.IssuerUri);
        }