2022-06-04 08:41:53 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2024-01-15 20:20:10 +00:00
|
|
|
# bthlabs-jsonrpc-django | (c) 2022-present Tomek Wójcik | MIT License
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
|
2022-06-04 08:41:53 +00:00
|
|
|
from django.contrib import admin
|
|
|
|
from django.urls import path
|
|
|
|
|
|
|
|
from bthlabs_jsonrpc_django import JSONRPCView, is_authenticated, is_staff
|
2024-01-15 20:20:10 +00:00
|
|
|
from bthlabs_jsonrpc_core.ext.jwt import ALGORITHMS, HMACKey, JWTCodec, KeyPair
|
|
|
|
|
|
|
|
|
|
|
|
class JWTRPCView(JSONRPCView):
|
|
|
|
codec = JWTCodec
|
|
|
|
|
|
|
|
def get_codec(self, request):
|
|
|
|
return JWTCodec(
|
|
|
|
KeyPair(
|
|
|
|
decode_key=HMACKey('thisisntasecrurekeydontuseitpls=', ALGORITHMS.HS256),
|
|
|
|
encode_key=HMACKey('thisisntasecrurekeydontuseitpls=', ALGORITHMS.HS256),
|
|
|
|
),
|
|
|
|
issuer='bthlabs_jsonrpc_django_example',
|
|
|
|
ttl=datetime.timedelta(seconds=3600),
|
|
|
|
)
|
|
|
|
|
2022-06-04 08:41:53 +00:00
|
|
|
|
|
|
|
urlpatterns = [
|
|
|
|
path('admin/', admin.site.urls),
|
|
|
|
path(
|
|
|
|
'rpc/admin',
|
2024-01-15 20:20:10 +00:00
|
|
|
JWTRPCView.as_view(
|
2022-06-04 08:41:53 +00:00
|
|
|
auth_checks=[is_authenticated, is_staff],
|
|
|
|
namespace='admin',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
path(
|
|
|
|
'rpc/private',
|
|
|
|
JSONRPCView.as_view(
|
|
|
|
auth_checks=[is_authenticated],
|
|
|
|
namespace='private',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
path('rpc', JSONRPCView.as_view()),
|
|
|
|
]
|