I am trying to protect the REST API based on the client IP address.
Introduce the blogging application with these sample requests:
/post/list
/post/create
/post/update/42
/post/delete/42
/comment/42/list
/comment/42/create
/comment/42/delete/1337
IP whitelists defined in appsettings.json :
"IpSecurity": {
"Author": "123.456.789.43,123.456.789.44",
"Admin": "123.456.789.42"
}
Here are examples of actions with the corresponding attributes RequireRolethat I would like to implement:
[HttpGet("post/list")]
public List<Post> List()
[RequireRole("Author")]
[HttpGet("post/create")]
public StandardResponse Create([FromBody]Post post)
[RequireRole("Admin")]
[HttpGet("post/delete/{id}")]
public StandardResponse Delete(int id)
Specific Injection from Launch
var IpSecurity = Configuration.GetSection("IpSecurity");
services.Configure<IpSecurityConfig>(IpSecurity);
Does this sound like a good idea?
Do I have to implement a custom authorization policy, middleware and / or filter for this?
How to implement an attribute RequireRole?
, IP, , t .