Giter Site home page Giter Site logo

Comments (8)

pgjones avatar pgjones commented on June 12, 2024

The credentials are stored in the app's config, which can be loaded from the environment or files (no need to store credentials in the code).

I'm not sure whether to add this functionality to Quart-Auth directly - it is quite easily to adapt and create your own basic_auth_required decorator based on the existing one e.g. for your use case (with check_auth):

def basic_auth_required(func: Callable) -> Callable:
    @wraps(func)
    async def wrapper(*args: Any, **kwargs: Any) -> Any:
        if has_request_context():
            auth = request.authorization
        elif has_websocket_context():
            auth = websocket.authorization
        else:
            raise RuntimeError("Not used in a valid request/websocket context")

        valid = await check_auth(auth)
        if valid:
            return await current_app.ensure_async(func)(*args, **kwargs)
        else:
            raise UnauthorizedBasicAuth()

    return wrapper

from quart-auth.

yan-hic avatar yan-hic commented on June 12, 2024

Thanks for the prompt reply ! Agreed it's easy but just suggesting merging the above while keeping the explicit user/pwd validation e.g. making the args mutually exclusive (user/pwd or validation function). Feel free to close, I am all set.

from quart-auth.

yan-hic avatar yan-hic commented on June 12, 2024

qq: do you monitor more - and do you prefer keep logs in - gitter, gitlab or github ? There are many channels you mentioned ;-)

from quart-auth.

pgjones avatar pgjones commented on June 12, 2024

I'm currently moving everything to github (watch this space...).

from quart-auth.

yan-hic avatar yan-hic commented on June 12, 2024

Just discovered a possible bug: when executing the wrapped function (past validation), if the function/view has no argument, you get TypeError: xxxx() takes 0 positional arguments but 2 were given
Workaround - for now - is to add a dummy arg array in the view definition i.e. async def xxx(*dummy_args):

from quart-auth.

pgjones avatar pgjones commented on June 12, 2024

Hmm, I'm not sure why it would error like that - could you share the stack trace?

from quart-auth.

yan-hic avatar yan-hic commented on June 12, 2024

OMG - embarrassing:

    @wraps(func)
    async def wrapper(*args, **kwargs):
        print_log(f'{session=}, {vars(session)}')
        if auth := request.authorization:
            if 'iw_cookies' not in session:
                if request.method == 'POST':
                    args = (await request.get_json()).get('userDefinedContext')

... I am reassigning args later in the code. Sorry for the oversight.

from quart-auth.

pgjones avatar pgjones commented on June 12, 2024

No worries, thanks for clarifying - a mystery closed :).

from quart-auth.

Related Issues (11)

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.