Comments (6)
Me too! I found that this code is all that you need for the [Authorize]
attribute to work as expected.
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
{
options.Audience = // UserPoolClientId
options.Authority = // https://cognito-idp.<Region>.amazonaws.com/<UserPoolId>
});
from aws-aspnet-cognito-identity-provider.
Me too! I found that this code is all that you need for the
[Authorize]
attribute to work as expected.services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { options.Audience = // UserPoolClientId options.Authority = // https://cognito-idp.<Region>.amazonaws.com/<UserPoolId> });
Thanks for the information. I'm not quite sure if this really solves the described problem. I think you can even remove the line services.AddCognitoIdentity(); completely and your solution would still work. It's just the standard implementation of an JWT bearer token for authentication/authorization. Can you use the cognito-specific features, such as [Authorize(Roles = "Admin")] with you solution?
from aws-aspnet-cognito-identity-provider.
I am also having the same problem.
from aws-aspnet-cognito-identity-provider.
I am also having the same problem
from aws-aspnet-cognito-identity-provider.
Hi @jochencschmidt,
I came across the useful article ASP.NET Core with AWS Lambda and Cognito which might be useful for configuring Cognito Group based authorization in an ASP.NET Core application. It has a section Groups and Policies which provides the following details to add a custom policy.
You can use [Authorize] to ensure that only logged-in users can access the Page/Controller/Route. However you’d probably like more fine-grained control, so for that you can add users to Cognito Groups. On the ASP.NET Core app, those groups are sent as part of the user Claims. You can create authorization polices during the Startup.Configure method as follows:
services.AddAuthorization(options =>
{
options.AddPolicy("AdminOnly", policy =>
policy.RequireAssertion(context =>
context.User.HasClaim(c => c.Type == "cognito:groups" && c.Value == "Admin")));
});
This creates a policy requiring the logged in user to be part of the Cognito group Admin. To use this on a Page/Controller/Route, refer to the policy name in the Authorize attribute:
[Authorize(Policy = "AdminOnly")]
Article Now generally available: the ASP.NET Core Identity Provider for Amazon Cognito also provides similar guidance.
Please let me know if this helps and let me know if this issue could be closed.
Thanks,
Ashish
from aws-aspnet-cognito-identity-provider.
This issue has not recieved a response in 2 weeks. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.
from aws-aspnet-cognito-identity-provider.
Related Issues (20)
- Ways of supporting social login HOT 2
- Security: Defaults require secrets be published in unencrypted configuration files. HOT 6
- Sample App is nonfunctional for core common use cases and actively misleads users, seems abandoned. HOT 6
- Getting error "Unable to get IAM security credentials from EC2 Instance Metadata Service." while trying to login HOT 4
- AWSCognitoClientOptions doesn't contain a Region property (which is required by AWS) HOT 5
- Use inclusive pronouns in documentation. HOT 2
- Any plans to support .NET 5.0? HOT 4
- Implementing MFA suppression via remembered devices, getting 'Invalid device key given.' exception HOT 6
- Sample not working properly - Unable to get IAM security credentials from EC2 Instance Metadata Service. HOT 3
- Unable to retrieve UserPoolClientId and UserPoolClientSecret form AWS Parameter Store HOT 4
- Ability to reload AWSOptions after ASP.NET Core Lambda Startup HOT 19
- How to retrieve the list of all roles (groups) HOT 3
- AmazonCognitoIdentityProviderClient Usage HOT 6
- RemovePasswordAsync() fails for an unconfirmed user HOT 4
- Sign Out from all "active sessions" HOT 4
- RevokeToken behavior for multiple logins
- Support for External Providers HOT 4
- Check Password for unconfirmed user. HOT 5
- PasswordSignInAsync or CheckPasswordSignInAsync and SignInAsync are not persisting auth cookie User.Identity.IsAuthenticated is false HOT 6
- We can no longer search or find users with this sdk HOT 3
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 aws-aspnet-cognito-identity-provider.