Bishwas-py / djapy

No bullshit, Django Rest API Framework
https://djapy.io
59 stars 3 forks source link

Auth mechanism added #6

Closed Bishwas-py closed 5 months ago

Bishwas-py commented 5 months ago

core/auth contains the mechanism for auth.


class BaseAuthMechanism:
    def __init__(self, permissions: list[str] = None, message_response: dict = None, *args, **kwargs):
        self.message_response = message_response or {"message": "Unauthorized"}
        self.permissions = permissions

    def authenticate(self, request: HttpRequest, *args, **kwargs):
        pass

    def authorize(self, request: HttpRequest, *args, **kwargs):
        pass

    def schema(self):
        return {}

    def app_schema(self):
        return {}

    def set_message_response(self, message_response: dict):
        self.message_response = message_response

BaseAuthMechanism can be inherited and new auth mechanism can be written.

Bishwas-py commented 5 months ago

schema is for the overall OpenAPI details, and app_schema is for the specific endpoint, to apply that schema.