Пример #1
0
 /// <summary>
 /// Constructs a new <see cref="SimpleHttpProvider"/>.
 /// </summary>
 /// <param name="httpClient">Custom http client to be used for making requests</param>
 /// <param name="serializer">A serializer for serializing and deserializing JSON objects.</param>
 public SimpleHttpProvider(HttpClient httpClient, ISerializer serializer = null)
 {
     // Null authProvider addresses https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/605.
     // We're reenabling this functionality that allowed setting a null authprovider.
     this.httpClient = httpClient ?? GraphClientFactory.Create(authenticationProvider: null);
     Serializer      = serializer ?? new Serializer();
 }
Пример #2
0
        /// <summary>
        /// Initialize a baseClient to use for the upload that does not have Auth enabled as the upload URLs explicitly do not need authentication.
        /// </summary>
        /// <param name="uploadUrl">Url to perform the upload to from the session</param>
        /// <returns></returns>
        private IBaseClient InitializeClient(string uploadUrl)
        {
            HttpClient httpClient = GraphClientFactory.Create(authenticationProvider: null); //no auth

            httpClient.SetFeatureFlag(FeatureFlag.FileUploadTask);
            return(new BaseClient(uploadUrl, httpClient));
        }
Пример #3
0
        /// <summary>
        /// Constructs a new <see cref="HttpProvider"/>.
        /// </summary>
        /// <param name="httpMessageHandler">An HTTP message handler to pass to the <see cref="HttpClient"/> for sending requests.</param>
        /// <param name="disposeHandler">Whether or not to dispose the client handler on Dispose().</param>
        /// <param name="authenticationProvider">The <see cref="IAuthenticationProvider"/> for authenticating request messages.</param>
        /// <param name="serializer">A serializer for serializing and deserializing JSON objects.</param>
        public HttpProvider(IAuthenticationProvider authenticationProvider, HttpMessageHandler httpMessageHandler, bool disposeHandler, ISerializer serializer)
        {
            this.disposeHandler     = disposeHandler;
            this.httpMessageHandler = httpMessageHandler ?? new HttpClientHandler {
                AllowAutoRedirect = false
            };
            this.Serializer = serializer ?? new Serializer();

            DelegatingHandler[] handlers = new DelegatingHandler[]
            {
                new RedirectHandler(),
                new RetryHandler(),
                new AuthenticationHandler(authenticationProvider)
            };

            GraphClientFactory.DefaultHttpHandler = () => this.httpMessageHandler;
            this.httpClient = GraphClientFactory.Create("v1.0", GraphClientFactory.Global_Cloud, handlers);
        }
Пример #4
0
        /// <summary>
        /// Constructs a new <see cref="HttpProvider"/>.
        /// </summary>
        /// <param name="httpMessageHandler">An HTTP message handler to pass to the <see cref="HttpClient"/> for sending requests.</param>
        /// <param name="disposeHandler">Whether or not to dispose the client handler on Dispose().</param>
        /// <param name="serializer">A serializer for serializing and deserializing JSON objects.</param>
        public HttpProvider(HttpMessageHandler httpMessageHandler, bool disposeHandler, ISerializer serializer)
        {
            this.disposeHandler     = disposeHandler;
            this.httpMessageHandler = httpMessageHandler;
            this.Serializer         = serializer ?? new Serializer();

            // NOTE: Override our pipeline when a httpMessageHandler is provided - httpMessageHandler can implement custom pipeline.
            // This check won't be needed once we re-write the HttpProvider to work with GraphClientFactory.
            if (this.httpMessageHandler == null)
            {
                this.httpMessageHandler = GraphClientFactory.GetNativePlatformHttpHandler();
                this.httpClient         = GraphClientFactory.Create(authenticationProvider: null, version: "v1.0", nationalCloud: GraphClientFactory.Global_Cloud, finalHandler: this.httpMessageHandler);
            }
            else
            {
                this.httpClient = new HttpClient(this.httpMessageHandler, this.disposeHandler);
            }

            this.httpClient.SetFeatureFlag(FeatureFlag.DefaultHttpProvider);
        }