Comments (1)
So to answer how, before I get some time to actually add examples;
// Arrange
var authorizationService = BuildAuthorizationService(services =>
{
services.AddAuthorization(options =>
{
options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage"));
});
});
var user = new ClaimsPrincipal(
new ClaimsIdentity(new Claim[] { new Claim("Permission", "CanViewPage") }));
// Act
var allowed = await authorizationService.AuthorizeAsync(user, "Basic");
// Assert
Assert.True(allowed);
Testing imperative code inside the controller would mean mocking up a lot more pieces, I'll have to think on the best way to do this.
from aspnetauthorizationworkshop.
Related Issues (20)
- Incorrect path in Add MVC step HOT 1
- Compatibility with Old Systems HOT 2
- Global authorization Config in Startup.cs Not working HOT 2
- Question: How do I add new claims after `HttpContext.Authentication.SignInAsync` has been called? HOT 7
- Include Windows Authentication Examples HOT 6
- Lacks documentation on persisting claims
- Resource based authorisation broken in Core 2 branch HOT 16
- 404 not 401 I think... HOT 1
- Missing comma
- Step 4: Simple Policies
- Step 6 Code Task.FromResult(0) incorrect in doc but OK in source code
- Step 8 Doc incorrect
- Step 7 code OK doc incorrect
- Any guidance for running this with EasyAuth in App Services? HOT 4
- Token Authentication things are missing? HOT 4
- Similar workshop for Windows Authentication HOT 1
- Please upgrade for 2.2 and 3.0 HOT 5
- Autorization HOT 1
- When adding MVC to the app, we need to check "include prerelease."
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aspnetauthorizationworkshop.