コード例 #1
0
            public OAuthMessageHandler(CDSWebApiServiceConfig configParam,
                                       HttpMessageHandler innerHandler)
                : base(innerHandler)
            {
                config = configParam;

                if (config.UserPrincipalName != null && config.Password != null)
                {
                    _credential = new UserPasswordCredential(config.UserPrincipalName, config.Password);
                }
                _authContext = new AuthenticationContext(config.Authority, false);
            }
コード例 #2
0
        public CDSWebApiService(CDSWebApiServiceConfig config)
        {
            this.config = config;
            HttpMessageHandler messageHandler = new OAuthMessageHandler(config,
                                                                        new HttpClientHandler());

            httpClient = new HttpClient(messageHandler)
            {
                BaseAddress = new Uri(config.Url + $"/api/data/v{config.Version}/")
            };

            httpClient.Timeout = TimeSpan.FromSeconds(config.TimeoutInSeconds);
            httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
            httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");
            httpClient.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));
            if (config.CallerObjectId != Guid.Empty)
            {
                httpClient.DefaultRequestHeaders.Add("CallerObjectId", config.CallerObjectId.ToString());
            }
        }