Beispiel #1
0
        public static void Main(string[] args)
        {
            InitConfig();

            ClientFlow.OcsUrl = GetConfigValue("Resource");

            var tenantId     = GetConfigValue("TenantId");
            var clientId     = GetConfigValue("ClientId");
            var clientSecret = GetConfigValue("ClientKey");

            ClientFlow.CreateAuthenticatedHttpClient(clientId, clientSecret);

            // Make an HTTP request to OCS using the authenticated client - since this is the first request, the AuthenticationHandler will
            // authenticate and acquire an Access Token and cache it.
            var response = ClientFlow.AuthenticatedHttpClient.GetAsync($"api/Tenants/{tenantId}").Result;

            response.EnsureSuccessStatusCode();
            Console.WriteLine(response.Content.ReadAsStringAsync());
            Console.WriteLine($"HTTP GET api/Tenants/{tenantId} successful");

            // Make another request to OCS - this call should use the cached Access Token.
            response = ClientFlow.AuthenticatedHttpClient.GetAsync($"api/Tenants/{tenantId}/Users").Result;
            response.EnsureSuccessStatusCode();
            Console.WriteLine($"HTTP GET api/Tenants/{tenantId}/Users successful");
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            InitConfig();

            ClientFlow.OcsUrl = GetConfigValue("Resource");

            var tenantId     = GetConfigValue("TenantId");
            var clientId     = GetConfigValue("ClientId");
            var clientSecret = GetConfigValue("ClientKey");
            var version      = GetConfigValue("ApiVersion");

            ClientFlow.CreateAuthenticatedHttpClient(clientId, clientSecret);

            // Make an HTTP request to OCS using the authenticated client - since this is the first request, the AuthenticationHandler will
            // authenticate and acquire an Access Token and cache it.
            try
            {
                var response = ClientFlow.AuthenticatedHttpClient.GetAsync($"api/{version}/Tenants/{tenantId}/Users").Result;
                response.EnsureSuccessStatusCode();
                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
                Console.WriteLine($"HTTP GET api/{version}/Tenants/{tenantId}/Users successful");
            }
            catch (AggregateException ex)
            {
                foreach (var inEx in ex.Flatten().InnerExceptions)
                {
                    Console.WriteLine($"Authentication failed with the following error: {inEx.Message}");
                }
                throw (ex);
            }

            // Make another request to OCS - this call should use the cached Access Token.
            try
            {
                var response = ClientFlow.AuthenticatedHttpClient.GetAsync($"api/{version}/Tenants/{tenantId}/Users").Result;
                response.EnsureSuccessStatusCode();
                Console.WriteLine($"HTTP GET api/{version}/Tenants/{tenantId}/Users successful");
            }
            catch (AggregateException ex)
            {
                foreach (var inEx in ex.Flatten().InnerExceptions)
                {
                    Console.WriteLine($"Authentication failed with the following error: {inEx.Message}");
                }
                throw (ex);
            }
        }