You've already forked hotpocket
BTHLABS-50: Safari Web extension
Co-authored-by: Tomek Wójcik <labs@tomekwojcik.pl> Co-committed-by: Tomek Wójcik <labs@tomekwojcik.pl>
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
from . import access_tokens # noqa: F401
|
||||
from . import auth # noqa: F401
|
||||
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from bthlabs_jsonrpc_core import register_method
|
||||
from django import db
|
||||
from django.http import HttpRequest
|
||||
|
||||
from hotpocket_soa.services import AccessTokensService
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@register_method('accounts.access_tokens.create')
|
||||
def create(request: HttpRequest,
|
||||
auth_key: str,
|
||||
meta: dict,
|
||||
) -> str:
|
||||
with db.transaction.atomic():
|
||||
try:
|
||||
assert 'extension_auth_key' in request.session, 'Auth key missing'
|
||||
assert request.session['extension_auth_key'] == auth_key, (
|
||||
'Auth key mismatch'
|
||||
)
|
||||
except AssertionError as exception:
|
||||
LOGGER.error(
|
||||
'Unable to issue access token: %s',
|
||||
exception,
|
||||
exc_info=exception,
|
||||
)
|
||||
raise
|
||||
|
||||
access_token = AccessTokensService().create(
|
||||
account_uuid=request.user.pk,
|
||||
origin=request.META['HTTP_ORIGIN'],
|
||||
meta=meta,
|
||||
)
|
||||
|
||||
request.session.pop('extension_auth_key')
|
||||
request.session.save()
|
||||
|
||||
return access_token.key
|
||||
@@ -0,0 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
|
||||
from bthlabs_jsonrpc_core import register_method
|
||||
from django.http import HttpRequest
|
||||
|
||||
|
||||
@register_method('accounts.auth.check')
|
||||
def check(request: HttpRequest) -> bool:
|
||||
return request.user.is_anonymous is False
|
||||
Reference in New Issue
Block a user