Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying NinjaAPI init parameters for global authentication setting #30

Open
jasalt opened this issue Sep 28, 2024 · 0 comments
Open

Comments

@jasalt
Copy link

jasalt commented Sep 28, 2024

Documentation https://django-ninja.dev/guides/authentication/ suggests setting auth=GlobalAuth() on NinjaAPI initialization for having authentication setting across endpoints without issuing it separately for every time.

Copying the example code here:

from ninja import NinjaAPI, Form
from ninja.security import HttpBearer


class GlobalAuth(HttpBearer):
    def authenticate(self, request, token):
        if token == "supersecret":
            return token


api = NinjaAPI(auth=GlobalAuth())

I couldn't find a way to do this while using the ninja helper which initializes NinjaAPI without parameters at:

api = self.ninja.NinjaAPI()

Not sure about the implications supporting this would have but for now I'll leave the helper for a moment and try import django-ninja directly (as mentioned in nanodjango docs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready
Development

No branches or pull requests

1 participant