Code Monkey home page Code Monkey logo

Comments (4)

thomaxxl avatar thomaxxl commented on August 13, 2024 1

I should've been more clear: you can check the http method from within the decorator and perform authentication only for the methods you want, something like this:

from flask import request

def test_decorator(func):
    
    def api_wrapper(*args, **kwargs):
        print(request.method, func) 
        if request.method in ("POST","PATCH","DELETE"):
            if not authorized: # Pseudo code
                raise AuthError
        return func(*args, **kwargs)

    return result

The api_wrapper will be called before the rest of the api so you can perform authentication there.

Is this what you meant?

However, i see the swagger generation is broken, I'll have to fix this and prepare an example by tomorrow.

from safrs.

thomaxxl avatar thomaxxl commented on August 13, 2024 1

Does this work for you?
https://github.com/thomaxxl/safrs/blob/master/examples/authentication/demo_post_auth.py

from safrs.

thomaxxl avatar thomaxxl commented on August 13, 2024

Hi, this is possible by using a custom decorator.
There's an example here: https://github.com/thomaxxl/safrs/blob/master/examples/authentication/demo_auth.py

However I see there are a number of problems with this in the latest version. I'll make some changes to make things more clear.

from safrs.

GabrielGhe avatar GabrielGhe commented on August 13, 2024

Thanks for replying. I meant that I'd like to add authentication to the POST/PUT/DELETE methods of the models (Not custom methods like in the example). Is there a way to do that?

from safrs.

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.