本文整理汇总了Python中pymacaroons.Macaroon.deserialize方法的典型用法代码示例。如果您正苦于以下问题:Python Macaroon.deserialize方法的具体用法?Python Macaroon.deserialize怎么用?Python Macaroon.deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymacaroons.Macaroon
的用法示例。
在下文中一共展示了Macaroon.deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_authorization_header
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import deserialize [as 别名]
def get_authorization_header(root, discharge):
"""
Bind root and discharge macaroons and return the authorization header.
"""
bound = Macaroon.deserialize(root).prepare_for_request(
Macaroon.deserialize(discharge)
)
return "Macaroon root={}, discharge={}".format(root, bound.serialize())
示例2: test_from_go_macaroon_json_v2
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import deserialize [as 别名]
def test_from_go_macaroon_json_v2(self):
# The following macaroon have been generated with
# https://github.com/go-macaroon/macaroon
# to test the deserialization.
json_v1 = '{"caveats":[{"cid":"fp caveat"},{"cid":"tp caveat",' \
'"vid":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAp_MgxHrfLnfvNuYDo' \
'zNKWTlRPPx6VemasWnPpJdAWE6FWmOuFX4sB4-a1oAURDp",' \
'"cl":"tp location"}],"location":"my location",' \
'"identifier":"my identifier",' \
'"signature":"483b3881c9990e5099cb6695da3164daa64da60417b' \
'caf9e9dc4c0a9968f6636"}'
json_v1_discharge = '{"caveats":[],"location":"tp location",' \
'"identifier":"tp caveat",' \
'"signature":"8506007f69ae3e6a654e0b9769f20dd9da5' \
'd2af7860070d6776c15989fb7dea6"}'
m = Macaroon.deserialize(json_v1, serializer=JsonSerializer())
discharge = Macaroon.deserialize(json_v1_discharge,
serializer=JsonSerializer())
assert_macaroon(m, discharge, MACAROON_V1)
binary_v1 = 'MDAxOWxvY2F0aW9uIG15IGxvY2F0aW9uCjAwMWRpZGVudGlmaWVyIG1' \
'5IGlkZW50aWZpZXIKMDAxMmNpZCBmcCBjYXZlYXQKMDAxMmNpZCB0cC' \
'BjYXZlYXQKMDA1MXZpZCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACn' \
'8yDEet8ud+825gOjM0pZOVE8/HpV6Zqxac+kl0BYToVaY64VfiwHj5r' \
'WgBREOkKMDAxM2NsIHRwIGxvY2F0aW9uCjAwMmZzaWduYXR1cmUgSDs' \
'4gcmZDlCZy2aV2jFk2qZNpgQXvK+encTAqZaPZjYK'
binary_v1_discharge = 'MDAxOWxvY2F0aW9uIHRwIGxvY2F0aW9uCjAwMTlpZGVud' \
'GlmaWVyIHRwIGNhdmVhdAowMDJmc2lnbmF0dXJlIIUGAH' \
'9prj5qZU4Ll2nyDdnaXSr3hgBw1ndsFZift96mCg'
m = Macaroon.deserialize(binary_v1)
discharge = Macaroon.deserialize(binary_v1_discharge)
assert_macaroon(m, discharge, MACAROON_V1)
json_v2 = '{"c":[{"i":"fp caveat"},{"i":"tp caveat",' \
'"v64":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAp_MgxHrfLnfvNuYDoz' \
'NKWTlRPPx6VemasWnPpJdAWE6FWmOuFX4sB4-a1oAURDp",' \
'"l":"tp location"}],"l":"my location","i":"my identifier",' \
'"s64":"SDs4gcmZDlCZy2aV2jFk2qZNpgQXvK-encTAqZaPZjY"}'
json_v2_discharge = '{"l":"tp location","i":"tp caveat","s64":"hQYAf2' \
'muPmplTguXafIN2dpdKveGAHDWd2wVmJ-33qY"}'
m = Macaroon.deserialize(json_v2, serializer=JsonSerializer())
discharge = Macaroon.deserialize(json_v2_discharge,
serializer=JsonSerializer())
assert_macaroon(m, discharge, MACAROON_V2)
binary_v2 = 'AgELbXkgbG9jYXRpb24CDW15IGlkZW50aWZpZXIAAglmcCBjYXZlYXQ' \
'AAQt0cCBsb2NhdGlvbgIJdHAgY2F2ZWF0BEgAAAAAAAAAAAAAAAAAAA' \
'AAAAAAAAAAAAACn8yDEet8ud+825gOjM0pZOVE8/HpV6Zqxac+kl0BY' \
'ToVaY64VfiwHj5rWgBREOkAAAYgSDs4gcmZDlCZy2aV2jFk2qZNpgQX' \
'vK+encTAqZaPZjY'
binary_v2_discharge = 'AgELdHAgbG9jYXRpb24CCXRwIGNhdmVhdAAABiCFBgB/a' \
'a4+amVOC5dp8g3Z2l0q94YAcNZ3bBWYn7fepg'
m = Macaroon.deserialize(binary_v2)
discharge = Macaroon.deserialize(binary_v2_discharge)
assert_macaroon(m, discharge, MACAROON_V2)
示例3: macaroon_from_dict
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import deserialize [as 别名]
def macaroon_from_dict(json_macaroon):
'''Return a pymacaroons.Macaroon object from the given
JSON-deserialized dict.
@param JSON-encoded macaroon as dict
@return the deserialized macaroon object.
'''
return Macaroon.deserialize(json.dumps(json_macaroon),
json_serializer.JsonSerializer())
示例4: get_store_authorization
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import deserialize [as 别名]
def get_store_authorization(
email, permissions=None, channels=None, store_env=None,
allowed_stores=None, snaps=None):
"""Return the serialised root and discharge macaroon.
Get a permissions macaroon from SCA and discharge it in SSO.
"""
headers = DEFAULT_HEADERS.copy()
# Request a SCA root macaroon with hard expiration in 180 days.
sca_data = {
'permissions': permissions or ['package_access'],
'expires': (
datetime.date.today() + datetime.timedelta(days=180)
).strftime('%Y-%m-%d 00:00:00')
}
if channels:
sca_data['channels'] = channels
if allowed_stores:
sca_data['store_ids'] = allowed_stores
if snaps:
sca_data['packages'] = [{'name': snap} for snap in snaps]
response = requests.request(
url='{}/dev/api/acl/'.format(CONSTANTS[store_env]['sca_base_url']),
method='POST', json=sca_data, headers=headers)
if response.status_code != 200:
error = response.json()['title']
raise CliError("Error {}: {}".format(response.status_code, error))
root = response.json()['macaroon']
caveat, = [
c for c in Macaroon.deserialize(root).third_party_caveats()
if c.location == CONSTANTS[store_env]['sso_location']
]
# Request a SSO discharge macaroon.
sso_data = {
'email': email,
'password': getpass.getpass('Password for {}: '.format(email)),
'caveat_id': caveat.caveat_id,
}
response = requests.request(
url='{}/api/v2/tokens/discharge'.format(
CONSTANTS[store_env]['sso_base_url']),
method='POST', json=sso_data, headers=headers)
# OTP/2FA is optional.
if (response.status_code == 401 and
response.json().get('code') == 'TWOFACTOR_REQUIRED'):
sys.stderr.write('Second-factor auth for {}: '.format(store_env))
sso_data.update({'otp': input()})
response = requests.request(
url='{}/api/v2/tokens/discharge'.format(
CONSTANTS[store_env]['sso_base_url']),
method='POST', json=sso_data, headers=headers)
discharge = response.json()['discharge_macaroon']
return root, discharge
示例5: test_deserializing
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import deserialize [as 别名]
def test_deserializing(self):
m = Macaroon.deserialize(
'MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaW\
VyIHdlIHVzZWQgb3VyIHNlY3JldCBrZXkKMDAxNmNpZCB0ZXN0ID0gY2F2ZWF0CjAwMmZzaWduYXR1\
cmUgGXusegRK8zMyhluSZuJtSTvdZopmDkTYjOGpmMI9vWcK'
)
assert_equal(
m.signature,
'197bac7a044af33332865b9266e26d493bdd668a660e44d88ce1a998c23dbd67'
)
示例6: test_deserializing_accepts_padding
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import deserialize [as 别名]
def test_deserializing_accepts_padding(self):
m = Macaroon.deserialize(
('MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVz'
'ZWQgb3VyIHNlY3JldCBrZXkKMDAxN2NpZCB0ZXN0ID0gYWNhdmVhdAowMDJmc2ln'
'bmF0dXJlIJRJ_V3WNJQnqlVq5eez7spnltwU_AXs8NIRY739sHooCg==')
)
assert_equal(
m.signature,
'9449fd5dd6349427aa556ae5e7b3eeca6796dc14fc05ecf0d21163bdfdb07a28'
)
示例7: test_serializing_deserializing_macaroon
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import deserialize [as 别名]
def test_serializing_deserializing_macaroon(self, key_id, loc, key):
assume(key_id and loc and key)
macaroon = Macaroon(
location=loc,
identifier=key_id,
key=key
)
deserialized = Macaroon.deserialize(macaroon.serialize())
assert_equal(macaroon.identifier, deserialized.identifier)
assert_equal(macaroon.location, deserialized.location)
assert_equal(macaroon.signature, deserialized.signature)
示例8: test_deserializing_json
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import deserialize [as 别名]
def test_deserializing_json(self):
m = Macaroon.deserialize(
'{"location": "http://mybank/", "identifier": "we used our secret \
key", "signature": "197bac7a044af33332865b9266e26d493bdd668a660e44d88ce1a998c2\
3dbd67", "caveats": [{"cl": null, "cid": "test = caveat", "vid": null}]}',
serializer=JsonSerializer()
)
assert_equal(
m.signature,
'197bac7a044af33332865b9266e26d493bdd668a660e44d88ce1a998c23dbd67'
)
示例9: test_serializing_v2
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import deserialize [as 别名]
def test_serializing_v2(self):
m = Macaroon(
location='http://mybank/',
identifier='we used our secret key',
key='this is our super secret key; only we should know it',
version=MACAROON_V2
)
m.add_first_party_caveat('test = caveat')
n = Macaroon.deserialize(m.serialize())
assert_equal(m.identifier_bytes, n.identifier_bytes)
assert_equal(m.version, n.version)
示例10: test_deserializing_json_v2
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import deserialize [as 别名]
def test_deserializing_json_v2(self):
m = Macaroon.deserialize(
'{"l": "http://mybank/", "i": "we used our secret key", "s": '
'"197bac7a044af33332"'
', "c": [{"l": null, "i": "test = caveat", "v": null}]}',
serializer=JsonSerializer()
)
assert_equal(
m.signature_bytes,
binascii.hexlify(b'197bac7a044af33332')
)
示例11: test_serializing_deserializing_json
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import deserialize [as 别名]
def test_serializing_deserializing_json(self):
m = Macaroon(
location='http://test/',
identifier='first',
key='secret_key_1'
)
m.add_first_party_caveat('test = caveat')
n = Macaroon.deserialize(
m.serialize(serializer=JsonSerializer()),
serializer=JsonSerializer()
)
assert_equal(m.signature, n.signature)
示例12: get_caveat_id
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import deserialize [as 别名]
def get_caveat_id(root):
"""
Returns the caveat_id generated by the SSO
"""
location = urlparse(LOGIN_URL).hostname
caveat, = [
c
for c in Macaroon.deserialize(root).third_party_caveats()
if c.location == location
]
return caveat.caveat_id
示例13: test_serializing_with_binary_v2
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import deserialize [as 别名]
def test_serializing_with_binary_v2(self):
identifier = base64.b64decode('AK2o+q0Aq9+bONkXw7ky7HAuhCLO9hhaMMc==')
m = Macaroon(
location='http://mybank/',
identifier=identifier,
key='this is our super secret key; only we should know it',
version=MACAROON_V2
)
m.add_first_party_caveat('test = caveat')
n = Macaroon.deserialize(m.serialize())
assert_equal(m.identifier_bytes, n.identifier_bytes)
assert_equal(m.version, n.version)
示例14: test_serializing_json_v2_with_binary
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import deserialize [as 别名]
def test_serializing_json_v2_with_binary(self):
id = base64.b64decode('AK2o+q0Aq9+bONkXw7ky7HAuhCLO9hhaMMc==')
m = Macaroon(
location='http://mybank/',
identifier=id,
key='this is our super secret key; only we should know it',
version=MACAROON_V2
)
assert_equal(
json.loads(m.serialize(serializer=JsonSerializer()))['i64'],
"AK2o-q0Aq9-bONkXw7ky7HAuhCLO9hhaMMc"
)
n = Macaroon.deserialize(
m.serialize(serializer=JsonSerializer()),
serializer=JsonSerializer()
)
assert_equal(m.identifier_bytes, n.identifier_bytes)
示例15: test_serializing_macaroon_with_first_and_third_caveats
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import deserialize [as 别名]
def test_serializing_macaroon_with_first_and_third_caveats(self):
m = Macaroon(
location='http://mybank/',
identifier='we used our other secret key',
key='this is a different super-secret key; \
never use the same secret twice'
)
m.add_first_party_caveat('account = 3735928559')
caveat_key = '4; guaranteed random by a fair toss of the dice'
identifier = 'this was how we remind auth of key/pred'
m.add_third_party_caveat('http://auth.mybank/', caveat_key, identifier)
n = Macaroon.deserialize(m.serialize())
assert_equal(
m.signature,
n.signature
)