mblackgeo / flask-cognito-lib

A Flask extension that supports protecting routes with AWS Cognito following OAuth 2.1 best practices
https://mblackgeo.github.io/flask-cognito-lib/
MIT License
57 stars 15 forks source link

Multi class authentication - any class from list #18

Closed kr4600 closed 1 year ago

kr4600 commented 1 year ago

Hi, I'm trying to manage access to flask resources to specific groups assigned in cognito. I have several roles that i'd like to give access to things that they really need.

For example: Admin page:

Editor page:


I've tried to add multiple groups into auth_required but it haven't worked out, because there's all() operator inside. https://github.com/mblackgeo/flask-cognito-lib/blob/c493f071cb58ce122429842d969735bcb1b4d53c/src/flask_cognito_lib/decorators.py#L174

Is it possible to add flag any=True to auth_required for that use case? Or should i completely change my approach to this problem?

mblackgeo commented 1 year ago

Yes this looks like a reasonable change to make, I will take a look at adding support for this feature.

mblackgeo commented 1 year ago

Now supported in version 1.5.0, you can use the decorator as follows:

@auth_required(groups=["admin", "editor"], any_group=True)