Code Monkey home page Code Monkey logo

django-ninja-apikey's Introduction

Django Ninja APIKey

Easy to use API key authentication for Django Ninja REST Framework


This is an unofficial Django app which makes it easy to manage API keys for the Django Ninja REST Framework.

Key Features:

  • Easy integration in your projects
  • Well integrated in the admin interface
  • Secure API keys due to hashing
  • Works with the standard user model

Installation

pip install django-ninja-apikey

Usage

Add ninja_apikey to your installed apps in your django project:

# settings.py

INSTALLED_APPS = [
    # ...
    "ninja_apikey",
]

Run the included migrations:

python manage.py migrate

Secure an api endpoint with the API keys:

# api.py

from ninja import NinjaAPI
from ninja_apikey.security import APIKeyAuth

#  ...

auth = APIKeyAuth()
api = NinjaAPI()

# ...

@api.get("/secure_endpoint", auth=auth)
def secure_endpoint(request):
    return f"Hello, {request.user}!" 

Or secure your whole api (or a specific router) with the API keys:

# api.py

from ninja import NinjaAPI
from ninja_apikey.security import APIKeyAuth

#  ...

api = NinjaAPI(auth=APIKeyAuth())

# ...

@api.get("/secure_endpoint")
def secure_endpoint(request):
    return f"Hello, {request.user}!" 

You can create now API keys from django's admin interface.

License

This project is licensed under the terms of the MIT license.

django-ninja-apikey's People

Contributors

mawassk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

django-ninja-apikey's Issues

typing

I'm getting this when running mypy:

user/api/api_key.py:6: error: Skipping analyzing "ninja_apikey.models": module is installed, but missing library stubs or py.typed marker  [import]

do you plan to add some type hints?

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.