Quickstart¶
Requirements:¶
- docker
- python3
- pip3
- aiolambda-cli:
- pip install -U aiolambda
Create project:¶
$ aiolambda-cli init jwt
OpenAPI specs:¶
Define microservice API specs, for example:
openapi: 3.0.0
info:
title: JWT Example
version: '1.0'
servers:
- url: /v1
tags:
- name: auth
description: "Generate token"
- name: secret
description: "Return secret response"
- name: ping
description: "Test service"
paths:
/auth/{user_id}:
get:
tags:
- auth
summary: Return JWT token
operationId: jwt.handlers.auth_handler
parameters:
- name: user_id
description: User unique identifier
in: path
required: true
example: 12
schema:
type: integer
responses:
'200':
description: JWT token
content:
'application/json':
schema:
type: string
/secret:
get:
tags:
- secret
summary: Return secret string
operationId: jwt.handlers.secret_handler
responses:
'200':
description: secret response
content:
'application/json':
schema:
$ref: '#/components/schemas/Secret'
security:
- jwt: ['secret']
/ping:
get:
tags:
- ping
summary: "Test service"
description: ""
operationId: "jwt.handlers.ping_handler"
responses:
'200':
description: successful operation
components:
schemas:
Secret:
type: "object"
properties:
user_id:
type: "string"
example: "12"
secret:
type: "string"
example: "wbevuec"
token_info:
$ref: '#/components/schemas/Token info'
Token info:
type: object
properties:
iss:
type: string
example: aiolambda
iat:
type: integer
example: 1545340057
exp:
type: integer
example: 1545340657
sub:
type: string
securitySchemes:
jwt:
type: http
scheme: bearer
bearerFormat: JWT
x-bearerInfoFunc: aiolambda.security.decode_token
Code¶
Define your custom handlers referenced in openAPI specs. For example, auth_handler:
async def auth_handler(user_id: str) -> Response:
return compose(
generate_token,
logger.debug,
return_200)(user_id)