-
-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from rafaelcaricio/using-api-to-auth-404
Auth 404 errors option
- Loading branch information
Showing
8 changed files
with
227 additions
and
79 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
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
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,43 @@ | ||
|
||
import logging | ||
from .operation import SecureOperation | ||
from .problem import problem | ||
|
||
logger = logging.getLogger('connexion.handlers') | ||
|
||
|
||
class AuthErrorHandler(SecureOperation): | ||
""" | ||
Wraps an error with authentication. | ||
""" | ||
|
||
def __init__(self, exception, security, security_definitions): | ||
""" | ||
This class uses the exception instance to produce the proper response problem in case the | ||
request is authenticated. | ||
:param exception: the exception to be wrapped with authentication | ||
:type exception: werkzeug.exceptions.HTTPException | ||
:param security: list of security rules the application uses by default | ||
:type security: list | ||
:param security_definitions: `Security Definitions Object | ||
<https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#security-definitions-object>`_ | ||
:type security_definitions: dict | ||
""" | ||
self.exception = exception | ||
SecureOperation.__init__(self, security, security_definitions) | ||
|
||
@property | ||
def function(self): | ||
""" | ||
Configured error auth handler. | ||
""" | ||
security_decorator = self.security_decorator | ||
logger.debug('... Adding security decorator (%r)', security_decorator, extra=vars(self)) | ||
return security_decorator(self.handle) | ||
|
||
def handle(self, *args, **kwargs): | ||
""" | ||
Actual handler for the execution after authentication. | ||
""" | ||
return problem(title=self.exception.name, detail=self.exception.description, status=self.exception.code) |
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
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
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 @@ | ||
swagger: "2.0" | ||
|
||
info: | ||
title: "{{title}}" | ||
version: "1.0" | ||
|
||
basePath: /v1.0 | ||
|
||
securityDefinitions: | ||
oauth: | ||
type: oauth2 | ||
flow: password | ||
tokenUrl: https://ouath.example/token | ||
x-tokenInfoUrl: https://ouath.example/token_info | ||
scopes: | ||
myscope: can do stuff | ||
|
||
security: | ||
- oauth: | ||
- myscope | ||
|
||
paths: | ||
/greeting/{name}: | ||
post: | ||
summary: Generate greeting | ||
description: Generates a greeting message. | ||
operationId: fakeapi.hello.post_greeting | ||
responses: | ||
200: | ||
description: greeting response | ||
schema: | ||
type: object | ||
parameters: | ||
- name: name | ||
in: path | ||
description: Name of the person to greet. | ||
required: true | ||
type: string |
Oops, something went wrong.