Compare commits
1 Commits
jwt-experi
...
openapi3
Author | SHA1 | Date | |
---|---|---|---|
4f4b959e9e
|
@ -20,9 +20,7 @@ RUN \
|
||||
pip3 install connexion && \
|
||||
pip3 install connexion[swagger-ui] && \
|
||||
pip3 install uwsgi && \
|
||||
pip3 install flask-cors && \
|
||||
pip3 install python-jose[cryptography] && \
|
||||
pip3 install six
|
||||
pip3 install flask-cors
|
||||
|
||||
RUN \
|
||||
mkdir -p ${APP_DIR} && \
|
||||
|
44
auth.py
44
auth.py
@ -1,44 +0,0 @@
|
||||
|
||||
import time
|
||||
|
||||
import connexion
|
||||
import six
|
||||
from werkzeug.exceptions import Unauthorized
|
||||
|
||||
from jose import JWTError, jwt
|
||||
|
||||
JWT_ISSUER = 'de.hottis.hausverwaltung'
|
||||
JWT_SECRET = 'streng_geheim'
|
||||
JWT_LIFETIME_SECONDS = 600
|
||||
JWT_ALGORITHM = 'HS256'
|
||||
|
||||
|
||||
def generate_token(user_id):
|
||||
timestamp = _current_timestamp()
|
||||
payload = {
|
||||
"iss": JWT_ISSUER,
|
||||
"iat": int(timestamp),
|
||||
"exp": int(timestamp + JWT_LIFETIME_SECONDS),
|
||||
"sub": str(user_id),
|
||||
}
|
||||
|
||||
return jwt.encode(payload, JWT_SECRET, algorithm=JWT_ALGORITHM)
|
||||
|
||||
|
||||
def decode_token(token):
|
||||
try:
|
||||
return jwt.decode(token, JWT_SECRET, algorithms=[JWT_ALGORITHM])
|
||||
except JWTError as e:
|
||||
six.raise_from(Unauthorized, e)
|
||||
|
||||
|
||||
def get_secret(user, token_info) -> str:
|
||||
return '''
|
||||
You are user_id {user} and the secret is 'wbevuec'.
|
||||
Decoded token claims: {token_info}.
|
||||
'''.format(user=user, token_info=token_info)
|
||||
|
||||
|
||||
def _current_timestamp() -> int:
|
||||
return int(time.time())
|
||||
|
454
swagger.yaml
454
swagger.yaml
@ -1,7 +1,7 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: Hausverwaltung-JWT
|
||||
version: "0.2"
|
||||
title: Hausverwaltung
|
||||
version: "0.1"
|
||||
|
||||
paths:
|
||||
/hv/objekte:
|
||||
@ -12,10 +12,12 @@ paths:
|
||||
responses:
|
||||
200:
|
||||
description: Successful response.
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/Objekt'
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Objekt'
|
||||
404:
|
||||
description: No Objekte available
|
||||
500:
|
||||
@ -28,13 +30,16 @@ paths:
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
type: integer
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
responses:
|
||||
200:
|
||||
description: Successful response.
|
||||
schema:
|
||||
$ref: '#/components/Objekt'
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: '#/components/schemas/Objekt'
|
||||
404:
|
||||
description: Objekt not found
|
||||
500:
|
||||
@ -47,10 +52,12 @@ paths:
|
||||
responses:
|
||||
200:
|
||||
description: Successful response.
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/Wohnung'
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Wohnung'
|
||||
404:
|
||||
description: No Wohnung available
|
||||
500:
|
||||
@ -63,15 +70,18 @@ paths:
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
type: integer
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
responses:
|
||||
200:
|
||||
description: Successful response.
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/Wohnung'
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Wohnung'
|
||||
404:
|
||||
description: No Wohnung available
|
||||
500:
|
||||
@ -84,13 +94,16 @@ paths:
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
type: integer
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
responses:
|
||||
200:
|
||||
description: Successful response.
|
||||
schema:
|
||||
$ref: '#/components/Wohnung'
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: '#/components/schemas/Wohnung'
|
||||
404:
|
||||
description: Wohnung not found
|
||||
500:
|
||||
@ -103,10 +116,12 @@ paths:
|
||||
responses:
|
||||
200:
|
||||
description: Successful response.
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/Mieter'
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Mieter'
|
||||
404:
|
||||
description: No Mieter available
|
||||
500:
|
||||
@ -119,13 +134,16 @@ paths:
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
type: integer
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
responses:
|
||||
200:
|
||||
description: Successful response.
|
||||
schema:
|
||||
$ref: '#/components/Mieter'
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: '#/components/schemas/Mieter'
|
||||
404:
|
||||
description: Mieter not found
|
||||
500:
|
||||
@ -138,13 +156,16 @@ paths:
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
type: integer
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
responses:
|
||||
200:
|
||||
description: Successful response.
|
||||
schema:
|
||||
$ref: '#/components/Forderung'
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: '#/components/schemas/Forderung'
|
||||
404:
|
||||
description: Forderung not found
|
||||
500:
|
||||
@ -157,15 +178,18 @@ paths:
|
||||
parameters:
|
||||
- name: mieter_id
|
||||
in: path
|
||||
type: integer
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
responses:
|
||||
200:
|
||||
description: Successful response.
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/Forderung'
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Forderung'
|
||||
404:
|
||||
description: No Forderung available
|
||||
500:
|
||||
@ -178,13 +202,16 @@ paths:
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
type: integer
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
responses:
|
||||
200:
|
||||
description: Successful response.
|
||||
schema:
|
||||
$ref: '#/components/Zahlung'
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: '#/components/schemas/Zahlung'
|
||||
404:
|
||||
description: Zahlung not found
|
||||
500:
|
||||
@ -197,15 +224,18 @@ paths:
|
||||
parameters:
|
||||
- name: mieter_id
|
||||
in: path
|
||||
type: integer
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
responses:
|
||||
200:
|
||||
description: Successful response.
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/Zahlung'
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Zahlung'
|
||||
404:
|
||||
description: No Zahlung available
|
||||
500:
|
||||
@ -218,19 +248,23 @@ paths:
|
||||
parameters:
|
||||
- name: mieter_id
|
||||
in: path
|
||||
type: integer
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
- name: year
|
||||
in: path
|
||||
type: integer
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
responses:
|
||||
200:
|
||||
description: Successful response
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/ZahlungForderung'
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/ZahlungForderung'
|
||||
404:
|
||||
description: No ZahlungForderung available
|
||||
500:
|
||||
@ -243,193 +277,159 @@ paths:
|
||||
parameters:
|
||||
- name: mieter_id
|
||||
in: path
|
||||
type: integer
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
- name: year
|
||||
in: path
|
||||
type: integer
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
responses:
|
||||
200:
|
||||
description: Successful response
|
||||
schema:
|
||||
$ref: '#/components/Saldo'
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: '#/components/schemas/Saldo'
|
||||
404:
|
||||
description: Neither Forderungen nor Zahlungen available
|
||||
500:
|
||||
description: Some server error
|
||||
/hv/zahlung:
|
||||
post:
|
||||
tags: [ "Zahlung" ]
|
||||
operationId: ZahlungenForderungen.put_zahlung
|
||||
summary: Inserts a new Zahlung
|
||||
parameters:
|
||||
- name: zahlung
|
||||
in: body
|
||||
schema:
|
||||
$ref: '#/components/Zahlung'
|
||||
responses:
|
||||
202:
|
||||
description: Zahlung successfully inserted
|
||||
500:
|
||||
description: Some server or database error
|
||||
/auth/{user_id}:
|
||||
get:
|
||||
tags: [ "jwt" ]
|
||||
summary: Return JWT token
|
||||
operationId: auth.generate_token
|
||||
parameters:
|
||||
- name: user_id
|
||||
description: User unique identifier
|
||||
in: path
|
||||
required: true
|
||||
example: 12
|
||||
schema:
|
||||
type: integer
|
||||
responses:
|
||||
'200':
|
||||
description: JWT token
|
||||
content:
|
||||
'text/plain':
|
||||
schema:
|
||||
type: string
|
||||
/secret:
|
||||
get:
|
||||
tags: [ "jwt" ]
|
||||
summary: Return secret string
|
||||
operationId: auth.get_secret
|
||||
responses:
|
||||
'200':
|
||||
description: secret response
|
||||
content:
|
||||
'text/plain':
|
||||
schema:
|
||||
type: string
|
||||
security:
|
||||
- jwt: ['secret']
|
||||
# /hv/zahlung:
|
||||
# post:
|
||||
# tags: [ "Zahlung" ]
|
||||
# operationId: ZahlungenForderungen.put_zahlung
|
||||
# summary: Inserts a new Zahlung
|
||||
# parameters:
|
||||
# - name: zahlung
|
||||
# in: body
|
||||
# schema:
|
||||
# $ref: '#/components/schemas/Zahlung'
|
||||
# responses:
|
||||
# 202:
|
||||
# description: Zahlung successfully inserted
|
||||
# 500:
|
||||
# description: Some server or database error
|
||||
|
||||
|
||||
components:
|
||||
Objekt:
|
||||
description: Objekt type
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
shortname:
|
||||
type: string
|
||||
flaeche:
|
||||
type: number
|
||||
Wohnung:
|
||||
description: Wohnung type
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
objekt:
|
||||
type: integer
|
||||
shortname:
|
||||
type: string
|
||||
flaeche:
|
||||
type: number
|
||||
objekt_shortname:
|
||||
type: string
|
||||
Mieter:
|
||||
description: Mieter type
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
objekt:
|
||||
type: integer
|
||||
wohnung:
|
||||
type: integer
|
||||
wohnung_shortname:
|
||||
type: string
|
||||
objekt_shortname:
|
||||
type: string
|
||||
anrede:
|
||||
type: string
|
||||
vorname:
|
||||
type: string
|
||||
nachname:
|
||||
type: string
|
||||
strasse:
|
||||
type: string
|
||||
plz:
|
||||
type: string
|
||||
ort:
|
||||
type: string
|
||||
telefon:
|
||||
type: string
|
||||
einzug:
|
||||
type: string
|
||||
auszug:
|
||||
type: string
|
||||
Forderung:
|
||||
description: Forderung type
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
mieter:
|
||||
type: integer
|
||||
datum:
|
||||
type: string
|
||||
betrag:
|
||||
type: number
|
||||
kommentar:
|
||||
type: string
|
||||
ref_wohnung:
|
||||
type: number
|
||||
Zahlung:
|
||||
description: Zahlung type
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
mieter:
|
||||
type: integer
|
||||
datum_ist:
|
||||
type: string
|
||||
datum_soll:
|
||||
type: string
|
||||
betrag:
|
||||
type: number
|
||||
kommentar:
|
||||
type: string
|
||||
ZahlungForderung:
|
||||
description: ZahlungForderung type
|
||||
type: object
|
||||
properties:
|
||||
zf_type:
|
||||
type: string
|
||||
id:
|
||||
type: integer
|
||||
datum_soll:
|
||||
type: string
|
||||
datum_ist:
|
||||
type: string
|
||||
betrag_zahlung:
|
||||
type: number
|
||||
betrag_forderung:
|
||||
type: number
|
||||
kommentar:
|
||||
type: string
|
||||
mieter:
|
||||
type: number
|
||||
Saldo:
|
||||
description: Saldo type
|
||||
type: object
|
||||
properties:
|
||||
forderungen:
|
||||
type: number
|
||||
zahlungen:
|
||||
type: number
|
||||
saldo:
|
||||
type: number
|
||||
securitySchemes:
|
||||
jwt:
|
||||
type: http
|
||||
scheme: bearer
|
||||
bearerFormat: JWT
|
||||
x-bearerInfoFunc: auth.decode_token
|
||||
schemas:
|
||||
Objekt:
|
||||
description: Objekt type
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
shortname:
|
||||
type: string
|
||||
flaeche:
|
||||
type: number
|
||||
Wohnung:
|
||||
description: Wohnung type
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
objekt:
|
||||
type: integer
|
||||
shortname:
|
||||
type: string
|
||||
flaeche:
|
||||
type: number
|
||||
objekt_shortname:
|
||||
type: string
|
||||
Mieter:
|
||||
description: Mieter type
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
objekt:
|
||||
type: integer
|
||||
wohnung:
|
||||
type: integer
|
||||
wohnung_shortname:
|
||||
type: string
|
||||
objekt_shortname:
|
||||
type: string
|
||||
anrede:
|
||||
type: string
|
||||
vorname:
|
||||
type: string
|
||||
nachname:
|
||||
type: string
|
||||
strasse:
|
||||
type: string
|
||||
plz:
|
||||
type: string
|
||||
ort:
|
||||
type: string
|
||||
telefon:
|
||||
type: string
|
||||
einzug:
|
||||
type: string
|
||||
auszug:
|
||||
type: string
|
||||
Forderung:
|
||||
description: Forderung type
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
mieter:
|
||||
type: integer
|
||||
datum:
|
||||
type: string
|
||||
betrag:
|
||||
type: number
|
||||
kommentar:
|
||||
type: string
|
||||
ref_wohnung:
|
||||
type: number
|
||||
Zahlung:
|
||||
description: Zahlung type
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
mieter:
|
||||
type: integer
|
||||
datum_ist:
|
||||
type: string
|
||||
datum_soll:
|
||||
type: string
|
||||
betrag:
|
||||
type: number
|
||||
kommentar:
|
||||
type: string
|
||||
ZahlungForderung:
|
||||
description: ZahlungForderung type
|
||||
type: object
|
||||
properties:
|
||||
zf_type:
|
||||
type: string
|
||||
id:
|
||||
type: integer
|
||||
datum_soll:
|
||||
type: string
|
||||
datum_ist:
|
||||
type: string
|
||||
betrag_zahlung:
|
||||
type: number
|
||||
betrag_forderung:
|
||||
type: number
|
||||
kommentar:
|
||||
type: string
|
||||
mieter:
|
||||
type: number
|
||||
Saldo:
|
||||
description: Saldo type
|
||||
type: object
|
||||
properties:
|
||||
forderungen:
|
||||
type: number
|
||||
zahlungen:
|
||||
type: number
|
||||
saldo:
|
||||
type: number
|
||||
|
Reference in New Issue
Block a user