Contains authentication parameters based on unauthorized response from resource server.
コード例 #1
0
        private IMsalRequest CreateRequest(
            AuthenticationParameters authParameters,
            bool isInteractive)
        {
            var authParams = authParameters.Clone();

            // "hack" to work around default constructors in legacy scenarios...
            if (string.IsNullOrWhiteSpace(authParams.ClientId))
            {
                authParams.ClientId = _msalClientConfiguration.DefaultClientId;
            }

            if (string.IsNullOrWhiteSpace(authParams.Authority))
            {
                authParams.Authority = _msalClientConfiguration.DefaultAuthority;
            }

            authParams.TelemetryCorrelationId = _guidService.NewGuid();
            authParams.Logger = _platformProxy.CreateLogger(
                authParams.TelemetryCorrelationId,
                _msalClientConfiguration);

            var webRequestManager = new WebRequestManager(
                _httpManager,
                _platformProxy.GetSystemUtils(),
                _environmentMetadata,
                authParams);
            var cacheManager = new CacheManager(_storageManager, authParams);

            if (isInteractive)
            {
                return(new MsalInteractiveRequest(webRequestManager, cacheManager, _browserFactory, authParams));
            }
            else
            {
                return(new MsalBackgroundRequest(
                           webRequestManager,
                           cacheManager,
                           _platformProxy.GetSystemUtils(),
                           authParams));
            }
        }
        /// <summary>
        /// Creates authentication parameters from the WWW-Authenticate header in response received from resource. This method expects the header to contain authentication parameters.
        /// </summary>
        /// <param name="authenticateHeader">Content of header WWW-Authenticate header</param>
        /// <returns>AuthenticationParameters object containing authentication parameters</returns>
        public static AuthenticationParameters CreateFromResponseAuthenticateHeader(string authenticateHeader)
        {
            if (string.IsNullOrWhiteSpace(authenticateHeader))
            {
                throw new ArgumentNullException("authenticateHeader");
            }

            authenticateHeader = authenticateHeader.Trim();

            // This also checks for cases like "BearerXXXX authorization_uri=...." and "Bearer" and "Bearer "
            if (!authenticateHeader.StartsWith(Bearer, StringComparison.OrdinalIgnoreCase)
                || authenticateHeader.Length < Bearer.Length + 2
                || !char.IsWhiteSpace(authenticateHeader[Bearer.Length]))
            {
                var ex = new ArgumentException(MsalErrorMessage.InvalidAuthenticateHeaderFormat, "authenticateHeader");
                PlatformPlugin.Logger.Error(null, ex);
                throw ex;
            }

            authenticateHeader = authenticateHeader.Substring(Bearer.Length).Trim();

            Dictionary<string, string> authenticateHeaderItems = EncodingHelper.ParseKeyValueList(authenticateHeader, ',', false, null);

            var authParams = new AuthenticationParameters();
            string param;
            authenticateHeaderItems.TryGetValue(AuthorityKey, out param);
            authParams.Authority = param;
            authenticateHeaderItems.TryGetValue(ResourceKey, out param);
            authParams.Resource = param;

            return authParams;
        }
コード例 #3
0
 /// <inheritdoc />
 public async Task <AuthenticationResult> AcquireTokenInteractivelyAsync(
     AuthenticationParameters authParameters,
     CancellationToken cancellationToken)
 {
     return(await SignInAsync(authParameters, cancellationToken).ConfigureAwait(false));
 }