From d4ebdfdc898678c62327d537a9b854e9c70ca48c Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 22 Nov 2017 20:07:01 +0200 Subject: Add: verified, parsed token as claims kwarg to callbacks --- apifw/bottleapp.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apifw/bottleapp.py b/apifw/bottleapp.py index 20e57ef..7e1572d 100644 --- a/apifw/bottleapp.py +++ b/apifw/bottleapp.py @@ -108,9 +108,10 @@ class BottleAuthorizationPlugin: def apply(self, callback, route): def wrapper(*args, **kwargs): - if self.needs_authorization(route): - self.assert_authorized(route) + claims = self.get_token_claims() + kwargs['claims'] = claims + self.assert_authorized(route, claims) return callback(*args, **kwargs) return wrapper @@ -122,10 +123,13 @@ class BottleAuthorizationPlugin: logging.debug('authz_routes: %r', self._authz_routes) return key in self._authz_routes - def assert_authorized(self, route): + def get_token_claims(self): value = self.get_authorization_header(bottle.request) token = self.parse_authorization_header(value) claims = self.parse_token(token) + return claims + + def assert_authorized(self, route, claims): self.check_issuer(claims) if not self.scope_allows_route(claims['scope'], route): self.raise_forbidden( -- cgit v1.2.1