Comments (3)
So no recommendation on how to do this?
from rimdev.featureflags.
That is an excellent question. @billbogaiv implemented something like this:
.UseWhen(
predicate: x =>
{
return
x.Request.Path.StartsWithSegments(featureFlagsOptions.ApiGetAllPath) ||
x.Request.Path.StartsWithSegments(featureFlagsOptions.ApiGetPath) ||
x.Request.Path.StartsWithSegments(featureFlagsOptions.ApiSetPath) ||
x.Request.Path.StartsWithSegments(featureFlagsOptions.UiPath);
},
configuration: x =>
{
// Custom authorization code, for example:
x.UseAuthorization(OpenIdConnectDefaults.AuthenticationScheme);
})
I'd like to see something cleaner in the future, but maybe this helps for the moment?
from rimdev.featureflags.
Some additional things you'll need (assuming < .NET Core 3):
/// <summary>
/// Consider removing once .NET Core 3.0 is stable => relies on EndpointRouting to work.
/// Ref. https://github.com/aspnet/AspNetCore/blob/v3.0.0-preview3-19153-02/src/Security/Authorization/Policy/src/AuthorizationAppBuilderExtensions.cs
/// </summary>
public static class AuthorizationAppBuilderExtensions
{
public static IApplicationBuilder UseAuthorization(
this IApplicationBuilder app,
string policyName)
{
if (string.IsNullOrEmpty(policyName))
{
throw new ArgumentNullException(nameof(policyName));
}
return app.UseMiddleware<AuthorizationMiddleware>(policyName);
}
}
and
/// <summary>
/// Consider removing once .NET Core 3.0 is stable => relies on EndpointRouting to work.
/// Ref. https://github.com/aspnet/AspNetCore/blob/v3.0.0-preview3-19153-02/src/Security/Authorization/Policy/src/AuthorizationMiddleware.cs.
/// </summary>
public class AuthorizationMiddleware
{
public AuthorizationMiddleware(
RequestDelegate next,
string policyName)
{
this.next = next;
this.policyName = policyName;
}
private readonly RequestDelegate next;
private readonly string policyName;
public async Task Invoke(
HttpContext httpContext,
IAuthorizationService authorizationService)
{
AuthorizationResult authorizationResult =
await authorizationService.AuthorizeAsync(httpContext.User, null, policyName);
if (!httpContext.User.Identity.IsAuthenticated && !authorizationResult.Succeeded)
{
await httpContext.ChallengeAsync();
return;
}
else if (httpContext.User.Identity.IsAuthenticated && !authorizationResult.Succeeded)
{
await httpContext.ForbidAsync();
return;
}
await next(httpContext);
}
}
from rimdev.featureflags.
Related Issues (8)
- CachedSqlFeatureProvider does not check stored features during initialization
- Customer UiPath Error
- How to register a custom IFeatureProvider HOT 6
- How to get the set connection string to the static options? HOT 3
- Allow FeatureFlagsOptions to set registration-type of features HOT 2
- Feature Flags V2 Concepts/Ideas HOT 2
- v2 Feature Flags HOT 1
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 rimdev.featureflags.