mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-27 20:36:16 +02:00
chore: rename api-key-macaroon
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
<q-card-section>
|
<q-card-section>
|
||||||
<code><span class="text-light-green">POST</span> /api/v1/payments</code>
|
<code><span class="text-light-green">POST</span> /api/v1/payments</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
|
||||||
<code>{"api_key": "<i>{{ wallet.inkey }}</i>"}</code><br />
|
<code>{"X-Api-Key": "<i>{{ wallet.inkey }}</i>"}</code><br />
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Body (application/json)</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Body (application/json)</h5>
|
||||||
<code>{"out": false, "amount": <int>, "memo": <string>}</code>
|
<code>{"out": false, "amount": <int>, "memo": <string>}</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Returns 201 CREATED (application/json)</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Returns 201 CREATED (application/json)</h5>
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
<q-card-section>
|
<q-card-section>
|
||||||
<code><span class="text-light-green">POST</span> /api/v1/payments</code>
|
<code><span class="text-light-green">POST</span> /api/v1/payments</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
|
||||||
<code>{"api_key": "{{ wallet.adminkey }}"}</code>
|
<code>{"X-Api-Key": "{{ wallet.adminkey }}"}</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Body (application/json)</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Body (application/json)</h5>
|
||||||
<code>{"out": true, "bolt11": <string>}</code>
|
<code>{"out": true, "bolt11": <string>}</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Returns 201 CREATED (application/json)</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Returns 201 CREATED (application/json)</h5>
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
<q-card-section>
|
<q-card-section>
|
||||||
<code><span class="text-light-blue">GET</span> /api/v1/payments/<checking_id></code>
|
<code><span class="text-light-blue">GET</span> /api/v1/payments/<checking_id></code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
|
||||||
<code>{"api_key": "{{ wallet.inkey }}"}</code>
|
<code>{"X-Api-Key": "{{ wallet.inkey }}"}</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Returns 200 OK (application/json)</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Returns 200 OK (application/json)</h5>
|
||||||
<code>{"paid": <bool>}</code>
|
<code>{"paid": <bool>}</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
from flask import g, jsonify, request
|
from flask import g, jsonify, request
|
||||||
|
|
||||||
from lnbits.core import core_app
|
from lnbits.core import core_app
|
||||||
from lnbits.decorators import api_check_wallet_macaroon, api_validate_post_request
|
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
|
||||||
from lnbits.helpers import Status
|
from lnbits.helpers import Status
|
||||||
from lnbits.settings import WALLET
|
from lnbits.settings import WALLET
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ from ..services import create_invoice, pay_invoice
|
|||||||
|
|
||||||
|
|
||||||
@core_app.route("/api/v1/payments", methods=["GET"])
|
@core_app.route("/api/v1/payments", methods=["GET"])
|
||||||
@api_check_wallet_macaroon(key_type="invoice")
|
@api_check_wallet_key("invoice")
|
||||||
def api_payments():
|
def api_payments():
|
||||||
if "check_pending" in request.args:
|
if "check_pending" in request.args:
|
||||||
for payment in g.wallet.get_payments(include_all_pending=True):
|
for payment in g.wallet.get_payments(include_all_pending=True):
|
||||||
@@ -21,7 +21,7 @@ def api_payments():
|
|||||||
return jsonify(g.wallet.get_payments()), Status.OK
|
return jsonify(g.wallet.get_payments()), Status.OK
|
||||||
|
|
||||||
|
|
||||||
@api_check_wallet_macaroon(key_type="invoice")
|
@api_check_wallet_key("invoice")
|
||||||
@api_validate_post_request(
|
@api_validate_post_request(
|
||||||
schema={
|
schema={
|
||||||
"amount": {"type": "integer", "min": 1, "required": True},
|
"amount": {"type": "integer", "min": 1, "required": True},
|
||||||
@@ -39,7 +39,7 @@ def api_payments_create_invoice():
|
|||||||
return jsonify({"checking_id": checking_id, "payment_request": payment_request}), Status.CREATED
|
return jsonify({"checking_id": checking_id, "payment_request": payment_request}), Status.CREATED
|
||||||
|
|
||||||
|
|
||||||
@api_check_wallet_macaroon(key_type="admin")
|
@api_check_wallet_key("admin")
|
||||||
@api_validate_post_request(schema={"bolt11": {"type": "string", "empty": False, "required": True}})
|
@api_validate_post_request(schema={"bolt11": {"type": "string", "empty": False, "required": True}})
|
||||||
def api_payments_pay_invoice():
|
def api_payments_pay_invoice():
|
||||||
try:
|
try:
|
||||||
@@ -63,7 +63,7 @@ def api_payments_create():
|
|||||||
|
|
||||||
|
|
||||||
@core_app.route("/api/v1/payments/<checking_id>", methods=["GET"])
|
@core_app.route("/api/v1/payments/<checking_id>", methods=["GET"])
|
||||||
@api_check_wallet_macaroon(key_type="invoice")
|
@api_check_wallet_key("invoice")
|
||||||
def api_payment(checking_id):
|
def api_payment(checking_id):
|
||||||
payment = g.wallet.get_payment(checking_id)
|
payment = g.wallet.get_payment(checking_id)
|
||||||
|
|
||||||
|
@@ -8,14 +8,14 @@ from lnbits.core.crud import get_user, get_wallet_for_key
|
|||||||
from .helpers import Status
|
from .helpers import Status
|
||||||
|
|
||||||
|
|
||||||
def api_check_wallet_macaroon(*, key_type: str = "invoice"):
|
def api_check_wallet_key(key_type: str = "invoice"):
|
||||||
def wrap(view):
|
def wrap(view):
|
||||||
@wraps(view)
|
@wraps(view)
|
||||||
def wrapped_view(**kwargs):
|
def wrapped_view(**kwargs):
|
||||||
try:
|
try:
|
||||||
g.wallet = get_wallet_for_key(request.headers["api_key"], key_type)
|
g.wallet = get_wallet_for_key(request.headers["X-Api-Key"], key_type)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return jsonify({"message": "`api_key` header missing."}), Status.BAD_REQUEST
|
return jsonify({"message": "`X-Api-Key` header missing."}), Status.BAD_REQUEST
|
||||||
|
|
||||||
if not g.wallet:
|
if not g.wallet:
|
||||||
return jsonify({"message": "Wrong keys."}), Status.UNAUTHORIZED
|
return jsonify({"message": "Wrong keys."}), Status.UNAUTHORIZED
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
from flask import g, jsonify, request
|
from flask import g, jsonify, request
|
||||||
|
|
||||||
from lnbits.core.crud import get_user
|
from lnbits.core.crud import get_user
|
||||||
from lnbits.decorators import api_check_wallet_macaroon, api_validate_post_request
|
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
|
||||||
from lnbits.helpers import Status
|
from lnbits.helpers import Status
|
||||||
|
|
||||||
from lnbits.extensions.amilk import amilk_ext
|
from lnbits.extensions.amilk import amilk_ext
|
||||||
@@ -9,7 +9,7 @@ from .crud import create_amilk, get_amilk, get_amilks, delete_amilk
|
|||||||
|
|
||||||
|
|
||||||
@amilk_ext.route("/api/v1/amilk", methods=["GET"])
|
@amilk_ext.route("/api/v1/amilk", methods=["GET"])
|
||||||
@api_check_wallet_macaroon(key_type="invoice")
|
@api_check_wallet_key("invoice")
|
||||||
def api_amilks():
|
def api_amilks():
|
||||||
wallet_ids = [g.wallet.id]
|
wallet_ids = [g.wallet.id]
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ def api_amilks():
|
|||||||
|
|
||||||
|
|
||||||
@amilk_ext.route("/api/v1/amilk", methods=["POST"])
|
@amilk_ext.route("/api/v1/amilk", methods=["POST"])
|
||||||
@api_check_wallet_macaroon(key_type="invoice")
|
@api_check_wallet_key("invoice")
|
||||||
@api_validate_post_request(schema={
|
@api_validate_post_request(schema={
|
||||||
"url": {"type": "string", "empty": False, "required": True},
|
"url": {"type": "string", "empty": False, "required": True},
|
||||||
"memo": {"type": "string", "empty": False, "required": True},
|
"memo": {"type": "string", "empty": False, "required": True},
|
||||||
@@ -33,7 +33,7 @@ def api_amilk_create():
|
|||||||
|
|
||||||
|
|
||||||
@amilk_ext.route("/api/v1/amilk/<amilk_id>", methods=["DELETE"])
|
@amilk_ext.route("/api/v1/amilk/<amilk_id>", methods=["DELETE"])
|
||||||
@api_check_wallet_macaroon(key_type="invoice")
|
@api_check_wallet_key("invoice")
|
||||||
def api_amilk_delete(amilk_id):
|
def api_amilk_delete(amilk_id):
|
||||||
amilk = get_amilk(amilk_id)
|
amilk = get_amilk(amilk_id)
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
from flask import g, jsonify, request
|
from flask import g, jsonify, request
|
||||||
|
|
||||||
from lnbits.core.crud import get_user
|
from lnbits.core.crud import get_user
|
||||||
from lnbits.decorators import api_check_wallet_macaroon, api_validate_post_request
|
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
|
||||||
from lnbits.helpers import Status
|
from lnbits.helpers import Status
|
||||||
|
|
||||||
from lnbits.extensions.paywall import paywall_ext
|
from lnbits.extensions.paywall import paywall_ext
|
||||||
@@ -9,7 +9,7 @@ from .crud import create_paywall, get_paywall, get_paywalls, delete_paywall
|
|||||||
|
|
||||||
|
|
||||||
@paywall_ext.route("/api/v1/paywalls", methods=["GET"])
|
@paywall_ext.route("/api/v1/paywalls", methods=["GET"])
|
||||||
@api_check_wallet_macaroon(key_type="invoice")
|
@api_check_wallet_key("invoice")
|
||||||
def api_paywalls():
|
def api_paywalls():
|
||||||
wallet_ids = [g.wallet.id]
|
wallet_ids = [g.wallet.id]
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ def api_paywalls():
|
|||||||
|
|
||||||
|
|
||||||
@paywall_ext.route("/api/v1/paywalls", methods=["POST"])
|
@paywall_ext.route("/api/v1/paywalls", methods=["POST"])
|
||||||
@api_check_wallet_macaroon(key_type="invoice")
|
@api_check_wallet_key("invoice")
|
||||||
@api_validate_post_request(schema={
|
@api_validate_post_request(schema={
|
||||||
"url": {"type": "string", "empty": False, "required": True},
|
"url": {"type": "string", "empty": False, "required": True},
|
||||||
"memo": {"type": "string", "empty": False, "required": True},
|
"memo": {"type": "string", "empty": False, "required": True},
|
||||||
@@ -33,7 +33,7 @@ def api_paywall_create():
|
|||||||
|
|
||||||
|
|
||||||
@paywall_ext.route("/api/v1/paywalls/<paywall_id>", methods=["DELETE"])
|
@paywall_ext.route("/api/v1/paywalls/<paywall_id>", methods=["DELETE"])
|
||||||
@api_check_wallet_macaroon(key_type="invoice")
|
@api_check_wallet_key("invoice")
|
||||||
def api_paywall_delete(paywall_id):
|
def api_paywall_delete(paywall_id):
|
||||||
paywall = get_paywall(paywall_id)
|
paywall = get_paywall(paywall_id)
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@ from flask import g, jsonify, request
|
|||||||
|
|
||||||
from lnbits.core.crud import get_user
|
from lnbits.core.crud import get_user
|
||||||
from lnbits.core.services import create_invoice
|
from lnbits.core.services import create_invoice
|
||||||
from lnbits.decorators import api_check_wallet_macaroon, api_validate_post_request
|
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
|
||||||
from lnbits.helpers import Status
|
from lnbits.helpers import Status
|
||||||
from lnbits.settings import WALLET
|
from lnbits.settings import WALLET
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ from .crud import create_tpos, get_tpos, get_tposs, delete_tpos
|
|||||||
|
|
||||||
|
|
||||||
@tpos_ext.route("/api/v1/tposs", methods=["GET"])
|
@tpos_ext.route("/api/v1/tposs", methods=["GET"])
|
||||||
@api_check_wallet_macaroon(key_type="invoice")
|
@api_check_wallet_key("invoice")
|
||||||
def api_tposs():
|
def api_tposs():
|
||||||
wallet_ids = [g.wallet.id]
|
wallet_ids = [g.wallet.id]
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ def api_tposs():
|
|||||||
|
|
||||||
|
|
||||||
@tpos_ext.route("/api/v1/tposs", methods=["POST"])
|
@tpos_ext.route("/api/v1/tposs", methods=["POST"])
|
||||||
@api_check_wallet_macaroon(key_type="invoice")
|
@api_check_wallet_key("invoice")
|
||||||
@api_validate_post_request(
|
@api_validate_post_request(
|
||||||
schema={
|
schema={
|
||||||
"name": {"type": "string", "empty": False, "required": True},
|
"name": {"type": "string", "empty": False, "required": True},
|
||||||
@@ -38,7 +38,7 @@ def api_tpos_create():
|
|||||||
|
|
||||||
|
|
||||||
@tpos_ext.route("/api/v1/tposs/<tpos_id>", methods=["DELETE"])
|
@tpos_ext.route("/api/v1/tposs/<tpos_id>", methods=["DELETE"])
|
||||||
@api_check_wallet_macaroon(key_type="invoice")
|
@api_check_wallet_key("invoice")
|
||||||
def api_tpos_delete(tpos_id):
|
def api_tpos_delete(tpos_id):
|
||||||
tpos = get_tpos(tpos_id)
|
tpos = get_tpos(tpos_id)
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ from flask import g, jsonify, request
|
|||||||
|
|
||||||
from lnbits.core.crud import get_user, get_wallet
|
from lnbits.core.crud import get_user, get_wallet
|
||||||
from lnbits.core.services import pay_invoice
|
from lnbits.core.services import pay_invoice
|
||||||
from lnbits.decorators import api_check_wallet_macaroon, api_validate_post_request
|
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
|
||||||
from lnbits.helpers import urlsafe_short_hash, Status
|
from lnbits.helpers import urlsafe_short_hash, Status
|
||||||
|
|
||||||
from lnbits.extensions.withdraw import withdraw_ext
|
from lnbits.extensions.withdraw import withdraw_ext
|
||||||
@@ -18,7 +18,7 @@ from .crud import (
|
|||||||
|
|
||||||
|
|
||||||
@withdraw_ext.route("/api/v1/links", methods=["GET"])
|
@withdraw_ext.route("/api/v1/links", methods=["GET"])
|
||||||
@api_check_wallet_macaroon(key_type="invoice")
|
@api_check_wallet_key("invoice")
|
||||||
def api_links():
|
def api_links():
|
||||||
wallet_ids = [g.wallet.id]
|
wallet_ids = [g.wallet.id]
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ def api_links():
|
|||||||
|
|
||||||
|
|
||||||
@withdraw_ext.route("/api/v1/links/<link_id>", methods=["GET"])
|
@withdraw_ext.route("/api/v1/links/<link_id>", methods=["GET"])
|
||||||
@api_check_wallet_macaroon(key_type="invoice")
|
@api_check_wallet_key("invoice")
|
||||||
def api_link_retrieve(link_id):
|
def api_link_retrieve(link_id):
|
||||||
link = get_withdraw_link(link_id)
|
link = get_withdraw_link(link_id)
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ def api_link_retrieve(link_id):
|
|||||||
|
|
||||||
@withdraw_ext.route("/api/v1/links", methods=["POST"])
|
@withdraw_ext.route("/api/v1/links", methods=["POST"])
|
||||||
@withdraw_ext.route("/api/v1/links/<link_id>", methods=["PUT"])
|
@withdraw_ext.route("/api/v1/links/<link_id>", methods=["PUT"])
|
||||||
@api_check_wallet_macaroon(key_type="invoice")
|
@api_check_wallet_key("invoice")
|
||||||
@api_validate_post_request(
|
@api_validate_post_request(
|
||||||
schema={
|
schema={
|
||||||
"title": {"type": "string", "empty": False, "required": True},
|
"title": {"type": "string", "empty": False, "required": True},
|
||||||
@@ -79,7 +79,7 @@ def api_link_create(link_id=None):
|
|||||||
|
|
||||||
|
|
||||||
@withdraw_ext.route("/api/v1/links/<link_id>", methods=["DELETE"])
|
@withdraw_ext.route("/api/v1/links/<link_id>", methods=["DELETE"])
|
||||||
@api_check_wallet_macaroon(key_type="invoice")
|
@api_check_wallet_key("invoice")
|
||||||
def api_link_delete(link_id):
|
def api_link_delete(link_id):
|
||||||
link = get_withdraw_link(link_id)
|
link = get_withdraw_link(link_id)
|
||||||
|
|
||||||
|
@@ -4,12 +4,12 @@ var EventHub = new Vue();
|
|||||||
|
|
||||||
var LNbits = {
|
var LNbits = {
|
||||||
api: {
|
api: {
|
||||||
request: function (method, url, macaroon, data) {
|
request: function (method, url, apiKey, data) {
|
||||||
return axios({
|
return axios({
|
||||||
method: method,
|
method: method,
|
||||||
url: url,
|
url: url,
|
||||||
headers: {
|
headers: {
|
||||||
'api_key': macaroon
|
'X-Api-Key': apiKey
|
||||||
},
|
},
|
||||||
data: data
|
data: data
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user