Coder Social home page Coder Social logo

Comments (7)

jb-alvarado avatar jb-alvarado commented on May 12, 2024 1

Ok, sorry, I will create one.

from protect-endpoints.

DDtKey avatar DDtKey commented on May 12, 2024

Thank you for the amazing package!

Thanks, I appreciate it!

In general, the question more about how routes & scopes works in actix-web. The easiest (but trivial) way is wrapping only needed scopes. For example:

App::new()
    .service(
        web::scope("/api/v1")
            .service(
                web::scope("/reservations")
                    .wrap(HttpAuthentication::bearer(validator))
                    .configure(reservations_controllers::secured_routes),
            )
            .service(web::scope("/auth").configure(auth_controller::routes))
    )
    .app_data(data.clone())

But I'm not sure if it suits you

from protect-endpoints.

stevenfukase avatar stevenfukase commented on May 12, 2024

Thank you for the quick response.
I'll just wrap individual handlers as you said

from protect-endpoints.

jb-alvarado avatar jb-alvarado commented on May 12, 2024

Hello @DDtKey , I run into the same issue. The trick with different scops works, but not in all situations.

Is there a way to use Role based authentication and map all requests without a authorization header to role Guest and then using #[has_any_role("Role::Guest", "Role::User", type = "Role")] ?

from protect-endpoints.

DDtKey avatar DDtKey commented on May 12, 2024

Hello @DDtKey , I run into the same issue. The trick with different scops works, but not in all situations.

Is there a way to use Role based authentication and map all requests without a authorization header to role Guest and then using #[has_any_role("Role::Guest", "Role::User", type = "Role")] ?

Just to clarify this, do you want actix-web-grants to consider not authorized users as Guests? Looks like another topic 🤔
It should be authorization logic in that case IMHO.

I mean you can assign the Guest during checking header(in method that you pass to middleware), like:

if auth_header.is_none() {
  return Role::Guest
}

from protect-endpoints.

jb-alvarado avatar jb-alvarado commented on May 12, 2024

Just to clarify this, do you want actix-web-grants to consider not authorized users as Guests? Looks like another topic thinking It should be authorization logic in that case IMHO.

Not exactly, it depends what is the most easiest way. It was only one idea I had, to give all non authenticated users the role guest. But I thought that maybe actix-web-grants has a way to handle this situations.

I mean you can assign the Guest during checking header(in method that you pass to middleware), like:

But that means I have to write my one middleware? I tried to implement something like that in the validator() function, but there the checking is to late already.

from protect-endpoints.

DDtKey avatar DDtKey commented on May 12, 2024

@jb-alvarado oh, I see your point. But it worth to create separate issue, I'm pretty sure that's not related one

from protect-endpoints.

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.