Example #1
0
def generate_token(header: Text, payload: Text) -> Text:
    """Generates tokens with valid MACs."""
    unsigned_compact = (_jwt_format.encode_header(header) + b'.' +
                        _jwt_format.encode_payload(payload))
    mac_value = MAC.compute_mac(unsigned_compact)
    return (unsigned_compact + b'.' +
            _jwt_format.encode_signature(mac_value)).decode('utf8')
Example #2
0
def generate_token_from_bytes(header: bytes, payload: bytes) -> Text:
    """Generates tokens from bytes with valid MACs."""
    unsigned_compact = (_jwt_format._base64_encode(header) + b'.' +
                        _jwt_format._base64_encode(payload))
    mac_value = MAC.compute_mac(unsigned_compact)
    return (unsigned_compact + b'.' +
            _jwt_format.encode_signature(mac_value)).decode('utf8')
Example #3
0
 def test_encode_decode_signature_success(self):
   signature = bytes([
       116, 24, 223, 180, 151, 153, 224, 37, 79, 250, 96, 125, 216, 173, 187,
       186, 22, 212, 37, 77, 105, 214, 191, 240, 91, 88, 5, 88, 83, 132, 141,
       121
   ])
   encoded = _jwt_format.encode_signature(signature)
   self.assertEqual(encoded, b'dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk')
   self.assertEqual(_jwt_format.decode_signature(encoded), signature)