authorization

undefined method `admin?' for nil:NilClass

时间秒杀一切 提交于 2019-12-21 05:04:51
问题 I followed railscast #250 Authentication from Scratch & got everthing wworking fine. Now I'm trying to only display edit & destroy links on my index page to admin user's. I've set up mu User database with a admin boolean field & tried putting a simple if statement in the view of another model (hikingtrails) to only display certain links to admin users but I get this error when I try it out, undefined method 'admin?' for nil:NilClass Database Schema create_table "users", :force => true do |t|

Show 404 error page after [Authorize] failure

落爺英雄遲暮 提交于 2019-12-21 04:49:19
问题 I have an action I want to restrict only to role "Admin". I did it like this: [Authorize(Roles = "Admin")] public ActionResult Edit(int id) After manually going under Controller/Edit/1 path I'm redirected to login page. Well, that isn't bad maybe, but I want to show 404 instead of it and try to stick using attributes for it. Is that possible? 回答1: Is that possible? Sure, you could write a custom authorize attribute: public class MyAuthorizeAttribute : AuthorizeAttribute { protected override

Authorization in GraphQL servers

情到浓时终转凉″ 提交于 2019-12-21 04:32:08
问题 How to handle Authorization in GraphQL servers? Shall I pass the JWT token in the Authentication header of every requests and check for the authorized user after resolve() and check for the role of user on every query and mutation 回答1: Introduction First of all, a common approach for authentication as you state is using a signed JWT that contains the id of the user making the request. Now let's have a look at the different parameters we can use when considering the authorization of a given

Why are `scope`-oriented actions (particularly `index` actions) treated differently in Pundit?

蓝咒 提交于 2019-12-21 04:11:24
问题 I am writing with respect to https://github.com/elabs/pundit#scopes I am under the impression that authorization should answer the question Are you allowed access to this resource? , i.e. a true / false answer. This is the case with all actions except index , which, according to Pundit's docs, should return different ActiveRecord::Relation 's depending on who is asking. For example, an admin gets scope.all , while a regular user gets scope.where(:published => true) . app/policies/post_policy

WEB API - Authorize at controller or action level (no authentication)

不打扰是莪最后的温柔 提交于 2019-12-21 04:09:09
问题 I have an existing API that has No Authentication. It`s a public Web API which several clients use by making simple requests. Now, there is the need to authorize access to a certain method. Is there any way to do this, keeping the rest of the controllers and respective methods "open" for the clients that already use this Web API? How can i identify if the request has permissions to access this "protected" method? 回答1: What you'll need to do is add an [Authorize] attribute to the methods you

How to invalidate .AspNet.ApplicationCookie after Adding user to Role using Asp.Net Identity 2?

佐手、 提交于 2019-12-21 04:04:15
问题 I have 2 questions related to that: 1) I need to invalidate.AspNet.ApplicationCookie after Adding / Removing some remote user to Role using Asp.Net Identity 2. I Tried to use UpdateSecurityStamp, but since no password or username is changed, SecurityStamp remains same. When I use ApplicationRoleManger I can see that User roles are updated but in User.Identity Claims they stay unchanged. 2) How does .AspNet.ApplicationCookie Validation work and how can I access it? I was trying to use this

Unit test AuthorizationHandler

我的梦境 提交于 2019-12-21 03:55:28
问题 I used the resource based authorization pattern in .NET Core 2.1 as described here. The only problem that I have is I have no idea on how to test my AuthorizationHandler cleanly. Anyone here did something like that already? AuthorizationHandler sample (from the above link): public class DocumentAuthorizationHandler : AuthorizationHandler<SameAuthorRequirement, Document> { protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, SameAuthorRequirement requirement,

Authorization method for REST API utilising Active Directory

冷暖自知 提交于 2019-12-21 03:30:34
问题 What is the best method of securing a REST Web API with the following requirements. The system has an Angular JS frontend with the REST APIs implemented in ASP.net. There are two "roles" in the system, users will have one of the roles. One role should allows access to some APIs (call it "VIEW"), the other role allows access to other APIs All users are in Active Directory, so if I have a username, I can check what role they are in- Some clients are on Windows boxes, the others are on Linux I

Django TokenAuthentication missing the 'Authorization' http header

◇◆丶佛笑我妖孽 提交于 2019-12-21 03:28:08
问题 I'm trying to use the TokenAuthentication with one of my views. As documented in https://www.django-rest-framework.org/api-guide/authentication/, I add the token I received from the login as an HTTP header called: 'Authorization' in the request I send. The problem is that in my unittests the authentication fails. Looking into the TokenAuthentication class I see that the header being checked is 'HTTP_AUTHORIZATION' and not 'Authorization' The view I'm using: class DeviceCreate(generics

Authorization and Entitlement solution on .Net like earlier in AzMan

元气小坏坏 提交于 2019-12-21 02:58:13
问题 What is the best way to achieve application authorization and entitlement in .Net. Earlier AzMan use to be the standard way. With the advent of provider model, at least roles are taken care of but I am not sure about the authorization & entitlement. I am looking at the ability to define and access operation level permissions for roles / users. What is the most suitable way to achieve the above? 回答1: According to this blog post the ClaimsAuthorizationManager API is 'next generation of AzMan'.