Code Monkey home page Code Monkey logo

Comments (5)

ganhammar avatar ganhammar commented on July 18, 2024 2

I was looking for the same, I ended up with the solution below:

public class AuthenticatedAuthorizationRequirement : IAuthorizationRequirement
{
  public Task Authorize(AuthorizationContext context)
  {
    if (!context.User.Identity.IsAuthenticated) {
      context.ReportError("Not authenticated");
    }

    return Task.CompletedTask;
  }
}

And add below to list of policies:

_.AddPolicy("AuthenticatedPolicy", p => p.AddRequirement(new AuthenticatedAuthorizationRequirement()));

Hope this helps!

from authorization.

BKB503 avatar BKB503 commented on July 18, 2024

@ganhammar I'm in same situation how to check user identity is authenticated ? before adding authorization on graphtype, I'm using default Authorize as it uses in controller

If I add below in valdation rule and setting back to context is working, is there any other way to check request is authenticated?
var httpContext = _httpContextAccessor.HttpContext;
var result1 = await httpContext.AuthenticateAsync("Bearer");
_httpContextAccessor.HttpContext.User = result1.Principal;

from authorization.

OpenSpacesAndPlaces avatar OpenSpacesAndPlaces commented on July 18, 2024

See #49 (comment) for a slightly longer example, but as @ganhammar showed, IAuthorizationRequirement is likely what you'd be looking for.

from authorization.

sungam3r avatar sungam3r commented on July 18, 2024

@kmanev073 This issue has already been resolved. Now you can use this requirement and that builder method.

from authorization.

sungam3r avatar sungam3r commented on July 18, 2024

Closed as resolved.

from authorization.

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.