Skip to content

Authorization fails with Flask Blueprints #11

@msdcanderson

Description

@msdcanderson

Hi,

Am I using flask-authz correctly?

My casbinmodel.conf:

[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

[role_definition]
g = _, _

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = g(r.sub, p.sub) && keyMatch(r.obj, p.obj) && regexMatch(r.act, p.act)

My security policy:

p, 1, /forms, POST
p, 1, /forms/1, GET
p, 1, /forms/2, GET

It looks like I have connected flask-authz up OK, when I do a POST request it works correctly, but when I do a GET (with a correctly logged in user) for '/forms/1', I get a fail:

2020-08-12 14:51:37,068 - INFO - Request: 1, /forms/<int:_id>, GET ---> False

It looks like the flask 'request.url_rule' is picking up forms/int:_id rather than /forms/1

My get resource:

@bp.route("/<int:_id>", methods=["GET"])
@jwt_required
@casbin_enforcer.enforcer
def get_form(_id):
    form = FormModel.find_by_id(_id)
    if not form:
        return {"message": gettext("FORM_NOT_FOUND")}, 404
    return form_schema.dump(form), 200

Thanks for any ideas :-)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions