-
-
Notifications
You must be signed in to change notification settings - Fork 780
Support Sanic #1250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Sanic #1250
Changes from 1 commit
49d03a4
d86e77e
7a7e7f1
1384647
e032476
e3d0430
0300a77
badfdef
11df083
03f4cb4
cd78f69
a1bafd7
3bec9f5
90cac20
01964b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,6 @@ | |
| import functools | ||
| import logging | ||
|
|
||
| import aiohttp | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kigawas can you PR this separately to the main connexion branch so that we don't mess with files we are not going to change?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the sanic dependencies do not include aiohttp, it's better to remove this to avoid potential import error
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pr proposed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries, I'll update later |
||
|
|
||
| from ..exceptions import OAuthProblem, OAuthResponseProblem, OAuthScopeProblem | ||
| from .security_handler_factory import AbstractSecurityHandlerFactory | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import logging | ||
|
|
||
| import httpx | ||
|
|
||
| from .async_security_handler_factory import AbstractAsyncSecurityHandlerFactory | ||
|
|
||
| logger = logging.getLogger("connexion.api.security") | ||
|
|
||
|
|
||
| class SanicSecurityHandlerFactory(AbstractAsyncSecurityHandlerFactory): | ||
| def __init__(self, pass_context_arg_name): | ||
| super(SanicSecurityHandlerFactory, self).__init__( | ||
| pass_context_arg_name=pass_context_arg_name | ||
| ) | ||
|
|
||
| def get_token_info_remote(self, token_info_url): | ||
| """ | ||
| Return a function which will call `token_info_url` to retrieve token info. | ||
|
|
||
| Returned function must accept oauth token in parameter. | ||
| It must return a token_info dict in case of success, None otherwise. | ||
|
|
||
| :param token_info_url: Url to get information about the token | ||
| :type token_info_url: str | ||
| :rtype: types.FunctionType | ||
| """ | ||
|
|
||
| async def wrapper(token): | ||
| async with httpx.AsyncClient() as client: | ||
| headers = {"Authorization": "Bearer {}".format(token)} | ||
| token_request = await client.get( | ||
| token_info_url, headers=headers, timeout=5 | ||
| ) | ||
| if token_request.status_code != 200: | ||
| return None | ||
| return token_request.json() | ||
|
|
||
| return wrapper |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| sanic>=20.3.0 | ||
| httpx>=0.16.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kigawas can we remove this space?