Skip to content

Commit

Permalink
Add example for AioHttpApp
Browse files Browse the repository at this point in the history
  • Loading branch information
exageraldo committed Feb 11, 2022
1 parent 1139b22 commit 88ae759
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 0 deletions.
37 changes: 37 additions & 0 deletions examples/aiohttp_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

# Connexion Auth Paths Extended - Example

Small connexion extension to add authentication into spec routes

## Run Locally

Clone the project

```bash
$ git clone https://github.com/exageraldo/connexion-auth-paths-extd.git
$ cd connexion-auth-paths-extd/
```

Go to the `examples/aiohttp_example` directory

```bash
$ cd examples/aiohttp_example/
```

Create a virtual env
```bash
$ python3 -m venv .venv
$ source .venv/bin/activate
```

Install dependencies

```bash
$ pip install -r requirements.txt
```

Start the server

```bash
$ python -m aiohttp.web -H localhost -P 8080 package.module:init_func
```
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions examples/aiohttp_example/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from connexion.extended.auth_paths_extd import AioHttpApp


def create_app(argv):
connexion_app = AioHttpApp(
__name__,
specification_dir='.',
auth_all_paths=True
)

connexion_app.add_api(
'openapi.yml',
base_path='/v1'
)
return connexion_app.app
File renamed without changes.
10 changes: 10 additions & 0 deletions examples/aiohttp_example/endpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from http import HTTPStatus
from aiohttp.web import Response


async def get_index():
return Response({}, status=HTTPStatus.NO_CONTENT)


async def get_greeting(name):
return Response({"welcome": name}, status=HTTPStatus.OK)
38 changes: 38 additions & 0 deletions examples/aiohttp_example/openapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
openapi: 3.0.1
info:
title: NEO Infrastructure API
version: 0.2.0

paths:
/:
get:
operationId: endpoints.get_index
responses:
"200":
description: Only to check if the API is available
content:
application/json:
schema:
type: object

/greeting/:
get:
operationId: endpoints.get_greeting
responses:
"200":
description: Show the welcome message json
content:
application/json:
schema:
type: object

components:
securitySchemes:
api_key:
type: apiKey
name: X-API-KEY
in: header
x-apikeyInfoFunc: auth.apikey_auth

security:
- api_key: []
2 changes: 2 additions & 0 deletions examples/aiohttp_example/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connexion-auth-paths-extd
connexion[aiohttp]~=2.10.0
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions examples/flask_example/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from connexion.exceptions import OAuthProblem


X_API_KEY = "some-string"

def apikey_auth(token, required_scopes):
if X_API_KEY != token:
raise OAuthProblem('Invalid token')
return {}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 88ae759

Please sign in to comment.