Giter Club home page Giter Club logo

Comments (6)

gilfoyle-predictile avatar gilfoyle-predictile commented on May 30, 2024 1

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.

jochencschmidt avatar jochencschmidt commented on May 30, 2024 1

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.

foo1976 avatar foo1976 commented on May 30, 2024 1

I am also having the same problem.

from aws-aspnet-cognito-identity-provider.

kawaic avatar kawaic commented on May 30, 2024

I am also having the same problem

from aws-aspnet-cognito-identity-provider.

ashishdhingra avatar ashishdhingra commented on May 30, 2024

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.

github-actions avatar github-actions commented on May 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.