-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1139b22
commit 88ae759
Showing
15 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.