public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
        {
            var challenge = new AuthenticationHeaderValue("Basic");
            context.Result = new AddChallengeOnUnauthorizedResult(challenge, context.Result);

            return Task.FromResult(0);
        }
		public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
		{
			// We do NOT return a Basic-Auth-Challenge header, so browser won't open an Auth-Dialog.
			////var challenge = new AuthenticationHeaderValue("Basic");
			////context.Result = new AddChallengeOnUnauthorizedResult(challenge, context.Result);
			return Task.FromResult(0);
		}
		public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
		{
			var authHeader = new AuthenticationHeaderValue(
				AuthorizationScheme,
				"realm=\"" + (Realm ?? "default") + "\""); // TODO: экранировать кавычки
			context.Result = new AddChallengeOnUnauthorizedResult(authHeader, context.Result);
			return Task.FromResult(0);
		}
        Task IAuthenticationFilter.ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
        {
            var userId = context.ActionContext.RequestContext.Principal.Identity.Name;

            context.Result = new SetIdentityResult(userId, context.Result);

            return Task.FromResult(0);
        }
		public async Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
		{
			await Task.Run(() =>
			{
				IPrincipal incomingPrincipal = context.ActionContext.RequestContext.Principal;
				Debug.WriteLine(String.Format("Incoming principal in custom auth filter ChallengeAsync method is authenticated: {0}", incomingPrincipal.Identity.IsAuthenticated));
			});		
		}
 public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
 {
     if (Thread.CurrentPrincipal != null)
     {
         return _done;
     }
     context.Result = new UnauthorizedResult(_challenges, context.Request);
     return _done;
 }
 public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
 {
     IPrincipal user = context.ActionContext.ControllerContext.RequestContext.Principal;
     if (null == user || !user.Identity.IsAuthenticated)
     {
         string parameter = string.Format("realm=\"{0}\"", context.Request.RequestUri.DnsSafeHost);
         AuthenticationHeaderValue challenge = new AuthenticationHeaderValue("Basic", parameter);
         context.Result = new UnauthorizedResult(new AuthenticationHeaderValue[] { challenge }, context.Request);
     }
     return Task.FromResult<object>(null);
 }
        public void OnChallenge(HttpAuthenticationChallengeContext context)
        {
            if (context == null) throw new ArgumentNullException("context");

            var dependencyScope = context.Request.GetDependencyScope();
            var lifetimeScope = dependencyScope.GetRequestLifetimeScope();

            var filters = lifetimeScope.Resolve<IEnumerable<Meta<Lazy<IAutofacAuthenticationFilter>>>>();

            foreach (var filter in filters.Where(FilterMatchesMetadata))
                filter.Value.Value.OnChallenge(context);
        }
 public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
 {
     context.Result = new ActionResultDelegate(context.Result, async (ct, next) =>
     {
         var res = await next.ExecuteAsync(ct);
         if(res.StatusCode == HttpStatusCode.Unauthorized)
         {
             res.Headers.WwwAuthenticate.Add(new AuthenticationHeaderValue("Basic", _realm));
         }
         return res;
     });
     return Task.FromResult<object>(null);
 }
Beispiel #10
0
        public System.Threading.Tasks.Task ChallengeAsync(System.Web.Http.Filters.HttpAuthenticationChallengeContext context, System.Threading.CancellationToken cancellationToken)
        {
            IPrincipal user = context.ActionContext.ControllerContext.RequestContext.Principal;

            if (user == null || !user.Identity.IsAuthenticated)
            {
                string parameters = string.Format("realm=\"{0}\"", context.Request.RequestUri.DnsSafeHost);
                AuthenticationHeaderValue challenge = new AuthenticationHeaderValue("Basic", parameters);

                context.Result = new UnauthorizedResult(new AuthenticationHeaderValue[] { challenge }, context.Request);
            }

            return(Task.FromResult <object>(null));
        }
 public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
 {
     string accessToken;
     if (!context.Request.TryGetAccessToken(out accessToken))
     {
         string clientId = "000000004810C359";
         string redirectUri = context.Request.RequestUri.ToString();
         string scope = "wl.signin%20wl.basic%20wl.offline_access";
         string url = "https://login.live.com/oauth20_authorize.srf";
         url += "?response_type=code&redirect_uri={0}&client_id={1}&scope={2}";
         url = String.Format(url, redirectUri, clientId, scope);
         context.Result = new RedirectResult(new Uri(url), context.Request);
     }
     return Task.FromResult<object>(null);
 }
        public async Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
        {
            IHttpActionResult result = _innerResult;
            IPrincipal originalPrincipal = _principalService.GetCurrentPrincipal(_request);
            HttpAuthenticationContext authenticationContext = new HttpAuthenticationContext(_context,
                originalPrincipal);

            for (int i = 0; i < _filters.Length; i++)
            {
                IAuthenticationFilter filter = _filters[i];
                await filter.AuthenticateAsync(authenticationContext, cancellationToken);

                IHttpActionResult error = authenticationContext.ErrorResult;

                // Short-circuit on the first authentication filter to provide an error result.
                if (error != null)
                {
                    result = error;
                    break;
                }
            }

            IPrincipal newPrincipal = authenticationContext.Principal;

            if (newPrincipal != originalPrincipal)
            {
                _principalService.SetCurrentPrincipal(newPrincipal, _request);
            }

            _controller.User = newPrincipal;

            // Run challenge on all filters (passing the result of each into the next). If a filter failed, the
            // challenges run on the failure result. If no filter failed, the challenges run on the original inner
            // result.
            HttpAuthenticationChallengeContext challengeContext = new HttpAuthenticationChallengeContext(_context,
                result);

            for (int i = 0; i < _filters.Length; i++)
            {
                IAuthenticationFilter filter = _filters[i];
                await filter.ChallengeAsync(challengeContext, cancellationToken);
            }

            Contract.Assert(challengeContext.Result != null);
            result = challengeContext.Result;

            return await result.ExecuteAsync(cancellationToken);
        }
        /// <inheritdoc />
        public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            HttpRequestMessage request = context.Request;

            if (request == null)
            {
                throw new InvalidOperationException(OwinResources.HttpAuthenticationChallengeContext_RequestMustNotBeNull);
            }

            IAuthenticationManager authenticationManager = GetAuthenticationManagerOrThrow(request);

            // Control the challenges that OWIN middleware adds later.
            authenticationManager.AuthenticationResponseChallenge = AddChallengeAuthenticationType(
                authenticationManager.AuthenticationResponseChallenge, _authenticationType);

            return TaskHelpers.Completed();
        }
        public Task ChallengeAsync(System.Web.Http.Filters.HttpAuthenticationChallengeContext context, System.Threading.CancellationToken cancellationToken)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            string parameter;

            if (String.IsNullOrEmpty(Realm))
            {
                parameter = null;
            }
            else
            {
                parameter = "realm=\"" + Realm + "\"";
            }

            var challenge = new System.Net.Http.Headers.AuthenticationHeaderValue(SignatureProvider.SignatureScheme, parameter);

            context.Result = new AddChallengeOnUnauthorizedResult(challenge, context.Result);
            return(Task.FromResult(0));
        }
Beispiel #15
0
 public void OnChallenge(HttpAuthenticationChallengeContext context)
 {
 }
 private void Authorize(HttpAuthenticationChallengeContext context)
 {
 }
 public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
 {
     return Task.Run(() => Authorize(context), cancellationToken);
 }
 /// <inheritdoc />
 public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
 {
     return _innerFilter.ChallengeAsync(context, cancellationToken);
 }
 public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
 {
     context.Result = new ResultWithChallenge(context.Result,
         context.Request,
         this.includeServerAuthorization,
         this.repository.GetCredentialsAsync);
    
     return Task.FromResult<object>(null);
 }
        public void ChallengeAsync_Throws_WhenRequestIsNull()
        {
            // Arrange
            IAuthenticationFilter filter = CreateProductUnderTest();
            IHttpActionResult result = CreateDummyActionResult();
            HttpAuthenticationChallengeContext context = new HttpAuthenticationChallengeContext(
                new HttpActionContext(), result);
            Assert.Null(context.Request);

            // Act & Assert
            InvalidOperationException exception = Assert.Throws<InvalidOperationException>(() =>
            {
                filter.ChallengeAsync(context, CancellationToken.None).ThrowIfFaulted();
            });
            Assert.Equal("HttpAuthenticationChallengeContext.Request must not be null.", exception.Message);
        }
 public async Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
 {
     //throw new NotImplementedException();
 }
Beispiel #22
0
 public async Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
 {
     await Task.Factory.StartNew(() => { }, cancellationToken);
 }
        private void Challenge(HttpAuthenticationChallengeContext context)
        {
            string parameter;

            if (String.IsNullOrEmpty(Realm)) parameter = null;
            else
                parameter = "realm=\"" + Realm + "\"";

            context.ChallengeWith("Basic", parameter);
        }
 Task IAuthenticationFilter.ChallengeAsync(HttpAuthenticationChallengeContext context, System.Threading.CancellationToken cancellationToken)
 {
     // nothing to do
     return Task.FromResult(0);
 }
        private void Challenge(HttpAuthenticationChallengeContext context)
        {
            string parameter;

            if (String.IsNullOrEmpty(Realm))
            {
                parameter = null;
            }
            else
            {
                // A correct implementation should verify that Realm does not contain a quote character unless properly
                // escaped (precededed by a backslash that is not itself escaped).
                parameter = "realm=\"" + Realm + "\"";
            }

            context.ChallengeWith("Basic", parameter);
        }
		public async Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
		{
			//no challenge
		}
 public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
 {
     return Task.CompletedTask;
 }
 public async Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
 {
   //  context.Result = new ResponseMessageResult(await context.Result.ExecuteAsync(cancellationToken));
 }
 public Task ChallengeAsync(HttpAuthenticationChallengeContext context, System.Threading.CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }
 public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
 {
     ExceptionTestsUtility.CheckForThrow(_throwAt, "AuthenticationChallenge");
     return Task.FromResult<object>(null);
 }
 public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
 {
     Challenge(context);
     return Task.FromResult(0);
 }
 public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
 {
     context.Result = new ResultWithChallenge(context.Result);
     return Task.CompletedTask;
 }