To go along with the 0.4 release of API Star, my third party app to add in JWT support has been updated. Much simpler API now
I did some interesting stuff to get around limitations of the new component API, namely, I wanted to have my top level
JWT component return itself or return a
JWTUser object, depending on the injected parameter. I overrode
can_handle_parameter to support handling both types. I would like to see
can_handle_parameter by default support
Union types, what do you think @tom ?
def resolve(self, authorization: http.Header, parameter: inspect.Parameter) -> Union[_JWT, JWTUser]: jwt = _JWT(self.settings) if parameter.annotation is JWT: return jwt token = get_token_from_header(authorization) jwt_user = jwt.decode(token) if jwt_user is None: raise AuthenticationFailed() return jwt_user def can_handle_parameter(self, parameter: inspect.Parameter): return parameter.annotation is JWT or parameter.annotation is JWTUser