asp.net-authorization

Asp.Net Core policy based authorization ends with 401 Unauthorized

落花浮王杯 提交于 2019-11-29 11:24:50
I am working on setting up a skeleton of custom policy based authorization which will have a set of business rules to authorized the currently logged on user. But, currently the skeleton always ends up with 401 Unauthorized . Here is my code, public class MyAuthorizationRequirement : IAuthorizationRequirement { public MyAuthorizationRequirement() { } } public class MyAuthorizationHandler : AuthorizationHandler<MyAuthorizationRequirement> { public MyAuthorizationHandler() { } protected override void Handle(AuthorizationContext context, MyAuthorizationRequirement requirement) { context.Succeed

Prevent FormsAuthenticationModule of intercepting ASP.NET Web API responses

六月ゝ 毕业季﹏ 提交于 2019-11-28 23:41:33
In ASP.NET the FormsAuthenticationModule intercepts any HTTP 401, and returns an HTTP 302 redirection to the login page. This is a pain for AJAX, since you ask for json and get the login page in html, but the status code is HTTP 200. What is the way of avoid this interception in ASP.NET Web API ? In ASP.NET MVC4 it is very easy to prevent this interception by ending explicitly the connection: public class MyMvcAuthFilter:AuthorizeAttribute { protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) { if (filterContext.HttpContext.Request.IsAjaxRequest() &&

ASP.NET MVC How to create a custom role provider

倖福魔咒の 提交于 2019-11-28 06:05:19
Being relatively new to ASP MVC, I'm unsure which would better suit my needs. I have built an intranet site using Windows authentication and I'm able to secure controllers and actions using the Active Directory roles, e.g. [Authorize(Roles="Administrators")] [Authorize(Users="DOMAIN\User")] public ActionResult SecureArea() { ViewBag.Message = "This is a secure area."; return View(); } I need to define my own security roles independent of the AD roles. The desired functionality is that authenticated users are granted access to specific actions according to one or more roles associated with

Asp.Net Core policy based authorization ends with 401 Unauthorized

别来无恙 提交于 2019-11-28 04:37:56
问题 I am working on setting up a skeleton of custom policy based authorization which will have a set of business rules to authorized the currently logged on user. But, currently the skeleton always ends up with 401 Unauthorized . Here is my code, public class MyAuthorizationRequirement : IAuthorizationRequirement { public MyAuthorizationRequirement() { } } public class MyAuthorizationHandler : AuthorizationHandler<MyAuthorizationRequirement> { public MyAuthorizationHandler() { } protected

Rich Twitter Digits/Google Auth with OpenIdDictServer

喜欢而已 提交于 2019-11-28 01:29:48
Our app requires sign-in by either mobile number or Google. We are planning to Twitter Digits for mobile number authentication. The flow of registration and authentication as I understand is as below: Mobile app does rich authentication with Twitter Digits or Google Sign In (it’s better user experience for the user to do rich auth instead of opening a web browser tab). Twitter Digits / Google Sign In returns Identity Token. Mobile app calls AuthServer to SignIn and presents Identity Token. Identity server validates the presented Identity Token with Digits service or Google Auth Service. Once

Prevent FormsAuthenticationModule of intercepting ASP.NET Web API responses

对着背影说爱祢 提交于 2019-11-27 14:56:46
问题 In ASP.NET the FormsAuthenticationModule intercepts any HTTP 401, and returns an HTTP 302 redirection to the login page. This is a pain for AJAX, since you ask for json and get the login page in html, but the status code is HTTP 200. What is the way of avoid this interception in ASP.NET Web API ? In ASP.NET MVC4 it is very easy to prevent this interception by ending explicitly the connection: public class MyMvcAuthFilter:AuthorizeAttribute { protected override void HandleUnauthorizedRequest

How to specify root (/) location in web.config?

自作多情 提交于 2019-11-27 05:31:36
问题 How does one specify root location in web.config to allow unauthenticated users access it? The root location is served by default.aspx, but users normally don't see default.aspx, they just see http://mysite.com/ . So I've added <location path="~/default.aspx"> <system.web> <authorization> <allow users="*"/> </authorization> </system.web> </location> Which works if user hits mysite.com/default.aspx , but if user hits mysite.com/ - he is still redirected to login page. I've tried <location path

MVC Core How to force / set global authorization for all actions?

与世无争的帅哥 提交于 2019-11-27 01:47:32
How to force / set global authorization for all actions in MVC Core ? I know how to register global filters - for example I have: Setup.cs services.AddMvc(options => { options.Filters.Add(new RequireHttpsAttribute()); }); and this works fine, but I can't add the same for Authorize: options.Filters.Add(new AuthorizeAttribute()); I have error: Cannot convert from 'Microsoft.AspNet.Authorization.AuthorizeAttribute()' to 'System.Type' (Method .Add() needs IFilterMetadata type) I know - from similar questions - that this works on MVC4-5... So something must changed on MVC Core... Someone have any

ASP.NET MVC How to create a custom role provider

断了今生、忘了曾经 提交于 2019-11-27 00:58:16
问题 Being relatively new to ASP MVC, I'm unsure which would better suit my needs. I have built an intranet site using Windows authentication and I'm able to secure controllers and actions using the Active Directory roles, e.g. [Authorize(Roles="Administrators")] [Authorize(Users="DOMAIN\User")] public ActionResult SecureArea() { ViewBag.Message = "This is a secure area."; return View(); } I need to define my own security roles independent of the AD roles. The desired functionality is that

MVC Core How to force / set global authorization for all actions?

爷,独闯天下 提交于 2019-11-26 09:44:26
问题 How to force / set global authorization for all actions in MVC Core ? I know how to register global filters - for example I have: Setup.cs services.AddMvc(options => { options.Filters.Add(new RequireHttpsAttribute()); }); and this works fine, but I can\'t add the same for Authorize: options.Filters.Add(new AuthorizeAttribute()); I have error: Cannot convert from \'Microsoft.AspNet.Authorization.AuthorizeAttribute()\' to \'System.Type\' (Method .Add() needs IFilterMetadata type) I know - from