/// <summary>
        /// Creates a pre-configured Microsoft Graph <see cref="HttpClient"/>.
        /// </summary>
        /// <param name="authConfig"></param>
        /// <returns></returns>
        public static HttpClient GetGraphHttpClient(AuthConfig authConfig)
        {
            IAuthenticationProvider authProvider = AuthenticationHelpers.GetAuthProvider(authConfig);
            HttpClient httpClient = GraphClientFactory.Create(authProvider);
            // Prepend new SDKVersionHeaders
            IEnumerable <string> previousSDKHeaders = httpClient.DefaultRequestHeaders.GetValues(CoreConstants.Headers.SdkVersionHeaderName);

            httpClient.DefaultRequestHeaders.Remove(CoreConstants.Headers.SdkVersionHeaderName);
            httpClient.DefaultRequestHeaders.Add(CoreConstants.Headers.SdkVersionHeaderName, previousSDKHeaders.Prepend(AuthModuleVersionHeaderValue));

            return(httpClient);
        }
Exemple #2
0
        /// <summary>
        /// Creates a pre-configured Microsoft Graph <see cref="HttpClient"/>.
        /// </summary>
        /// <param name="authContext"></param>
        /// <returns></returns>
        public static HttpClient GetGraphHttpClient(IAuthContext authContext = null)
        {
            authContext = authContext ?? GraphSession.Instance.AuthContext;
            if (authContext is null)
            {
                throw new AuthenticationException(ErrorConstants.Message.MissingAuthContext);
            }

            IAuthenticationProvider authProvider = AuthenticationHelpers.GetAuthProvider(authContext);

            return(GetGraphHttpClient(authProvider));
        }
Exemple #3
0
        /// <summary>
        /// Creates a pre-configured Microsoft Graph <see cref="HttpClient"/>.
        /// </summary>
        /// <param name="authConfig"></param>
        /// <returns></returns>
        public static HttpClient GetGraphHttpClient(AuthConfig authConfig)
        {
            IAuthenticationProvider   authProvider    = AuthenticationHelpers.GetAuthProvider(authConfig);
            IList <DelegatingHandler> defaultHandlers = GraphClientFactory.CreateDefaultHandlers(authProvider);

            // Register ODataQueryOptionsHandler after AuthHandler.
            defaultHandlers.Insert(1, (new ODataQueryOptionsHandler()));

            HttpClient httpClient = GraphClientFactory.Create(defaultHandlers);

            // Prepend new SDKVersionHeaders
            IEnumerable <string> previousSDKHeaders = httpClient.DefaultRequestHeaders.GetValues(CoreConstants.Headers.SdkVersionHeaderName);

            httpClient.DefaultRequestHeaders.Remove(CoreConstants.Headers.SdkVersionHeaderName);
            httpClient.DefaultRequestHeaders.Add(CoreConstants.Headers.SdkVersionHeaderName, previousSDKHeaders.Prepend(AuthModuleVersionHeaderValue));

            return(httpClient);
        }
Exemple #4
0
        /// <summary>
        /// Creates a pre-configured Microsoft Graph <see cref="HttpClient"/>.
        /// </summary>
        /// <param name="authContext"></param>
        /// <returns></returns>
        public static HttpClient GetGraphHttpClient(IAuthContext authContext = null)
        {
            authContext = authContext ?? GraphSession.Instance.AuthContext;
            if (authContext is null)
            {
                throw new AuthenticationException(ErrorConstants.Message.MissingAuthContext);
            }

            IAuthenticationProvider   authProvider    = AuthenticationHelpers.GetAuthProvider(authContext);
            IList <DelegatingHandler> defaultHandlers = GraphClientFactory.CreateDefaultHandlers(authProvider);

            // Register ODataQueryOptionsHandler after AuthHandler.
            defaultHandlers.Insert(1, (new ODataQueryOptionsHandler()));

            HttpClient httpClient = GraphClientFactory.Create(defaultHandlers);

            // Prepend new SDKVersionHeaders
            PrependNewSDKVersionHeaders(httpClient);

            return(httpClient);
        }
Exemple #5
0
        /// <summary>
        /// Creates a pre-configured Microsoft Graph <see cref="HttpClient"/>.
        /// </summary>
        /// <param name="authConfig"></param>
        /// <returns></returns>
        public static HttpClient GetGraphHttpClient(IAuthContext authConfig = null)
        {
            authConfig = authConfig ?? GraphSession.Instance.AuthContext;
            if (authConfig is null)
            {
                throw new AuthenticationException(ErrorConstants.Message.MissingAuthContext);
            }

            IAuthenticationProvider   authProvider    = AuthenticationHelpers.GetAuthProvider(authConfig);
            IList <DelegatingHandler> defaultHandlers = GraphClientFactory.CreateDefaultHandlers(authProvider);

            // Register ODataQueryOptionsHandler after AuthHandler.
            defaultHandlers.Insert(1, (new ODataQueryOptionsHandler()));

            HttpClient httpClient = GraphClientFactory.Create(defaultHandlers);

            // Prepend new SDKVersionHeaders
            IEnumerable <string> previousSDKHeaders = httpClient.DefaultRequestHeaders.GetValues(CoreConstants.Headers.SdkVersionHeaderName);

            httpClient.DefaultRequestHeaders.Remove(CoreConstants.Headers.SdkVersionHeaderName);
            httpClient.DefaultRequestHeaders.Add(CoreConstants.Headers.SdkVersionHeaderName, previousSDKHeaders.Prepend(AuthModuleVersionHeaderValue));

            return(httpClient);
        }