Created
April 1, 2019 22:49
-
-
Save kevinseelbach/3eab31f779adf2082b3db56bc6bcb097 to your computer and use it in GitHub Desktop.
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
from virgil_sdk.cards import card_manager | |
class CardManager(card_manager.CardManager): | |
# THIS IS A DIRECT COPY OF THE VIRGIL CardManager, just copied here to explain the issue | |
def search_card(self, identity): | |
# THIS IS A DIRECT COPY OF THE original method (without docs), just copied here to explain the issue | |
if not identity: | |
raise ValueError("Missing identity for search") | |
token_context = TokenContext(None, "search") | |
### | |
# KS: This next line is how the bug will get triggered (depending on what kind of AccessTokenProvider you use) | |
### | |
access_token = self._access_token_provider.get_token(token_context) | |
raw_cards = self.__try_execute(self.card_client.search_card, identity, access_token, token_context) | |
cards = list(map(lambda x: Card.from_signed_model(self._card_crypto, x), raw_cards)) | |
# omitted rest for brevity | |
class CallbackJwtProvider(AccessTokenProvider): | |
"""Exact copy of Virgil CallbackJwt ... just for this explanation | |
""" | |
def __init__(self, | |
get_token_callback # type: function | |
): | |
self.__get_token_callback = get_token_callback | |
def get_token(self, token_context): | |
if token_context: | |
return Jwt.from_string(self.__get_token_callback(token_context)) | |
else: | |
raise ValueError("Empty token context") | |
# | |
# TokenContext is a simple class with 4 properties - operation, identity, force_reload & service | |
# | |
def generate_jwt(token_context: TokenContext) -> str: | |
token = GENERATOR.generate_token(token_context.identity).to_string() | |
return token | |
def get_token_from_server(token_context: TokenContext) -> str: | |
"""virgil_sdk.cards.card_manager.CardManager calls | |
`self._access_token_provider.get_token(token_context)` internally when operations requiring a token are called | |
- search_card, get_card, etc. | |
""" | |
# no-op wrapper | |
return generate_jwt(token_context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment