Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_authorize_url__fail_with_implicit(self):
authenticator = prawcore.TrustedAuthenticator(
REQUESTOR, CLIENT_ID, CLIENT_SECRET, REDIRECT_URI
)
self.assertRaises(
prawcore.InvalidInvocation,
authenticator.authorize_url,
"temporary",
["identity", "read"],
"a_state",
implicit=True,
)
def test_authorize_url(self):
authenticator = prawcore.TrustedAuthenticator(
REQUESTOR, CLIENT_ID, CLIENT_SECRET, REDIRECT_URI
)
url = authenticator.authorize_url(
"permanent", ["identity", "read"], "a_state"
)
self.assertIn("client_id={}".format(CLIENT_ID), url)
self.assertIn("duration=permanent", url)
self.assertIn("response_type=code", url)
self.assertIn("scope=identity+read", url)
self.assertIn("state=a_state", url)
def test_revoke_token__with_refresh_token_hint(self):
authenticator = prawcore.TrustedAuthenticator(
REQUESTOR, CLIENT_ID, CLIENT_SECRET
)
with Betamax(REQUESTOR).use_cassette(
"TrustedAuthenticator_revoke_token__with_refresh_token_hint"
):
authenticator.revoke_token("dummy token", "refresh_token")
def test_initialize__with_trusted_authenticator(self):
authenticator = prawcore.TrustedAuthenticator(None, None, None)
self.assertRaises(
prawcore.InvalidInvocation,
prawcore.DeviceIDAuthorizer,
authenticator,
)
def setUp(self):
self.authentication = prawcore.TrustedAuthenticator(
REQUESTOR, CLIENT_ID, CLIENT_SECRET
)
def __init__(self):
super(InvalidAuthorizer, self).__init__(
prawcore.TrustedAuthenticator(REQUESTOR, CLIENT_ID, CLIENT_SECRET)
)
def test_revoke_token(self):
authenticator = prawcore.TrustedAuthenticator(
REQUESTOR, CLIENT_ID, CLIENT_SECRET
)
with Betamax(REQUESTOR).use_cassette(
"TrustedAuthenticator_revoke_token"
):
authenticator.revoke_token("dummy token")
def main():
"""Provide the program's entry point when directly executed."""
if len(sys.argv) < 2:
print("Usage: {} SCOPE...".format(sys.argv[0]))
return 1
authenticator = prawcore.TrustedAuthenticator(
prawcore.Requestor("prawcore_refresh_token_example"),
os.environ["PRAWCORE_CLIENT_ID"],
os.environ["PRAWCORE_CLIENT_SECRET"],
os.environ["PRAWCORE_REDIRECT_URI"],
)
state = str(random.randint(0, 65000))
url = authenticator.authorize_url("permanent", sys.argv[1:], state)
print(url)
client = receive_connection()
data = client.recv(1024).decode("utf-8")
param_tokens = data.split(" ", 2)[1].split("?", 1)[1].split("&")
params = {
key: value
for (key, value) in [token.split("=") for token in param_tokens]
def main():
"""Provide the program's entry point when directly executed."""
if len(sys.argv) != 2:
print("Usage: {} USERNAME".format(sys.argv[0]))
return 1
caching_requestor = prawcore.Requestor(
"prawcore_device_id_auth_example", session=CachingSession()
)
authenticator = prawcore.TrustedAuthenticator(
caching_requestor,
os.environ["PRAWCORE_CLIENT_ID"],
os.environ["PRAWCORE_CLIENT_SECRET"],
)
authorizer = prawcore.ReadOnlyAuthorizer(authenticator)
authorizer.refresh()
user = sys.argv[1]
with prawcore.session(authorizer) as session:
data1 = session.request("GET", "/api/v1/user/{}/trophies".format(user))
with prawcore.session(authorizer) as session:
data2 = session.request("GET", "/api/v1/user/{}/trophies".format(user))
for trophy in data1["data"]["trophies"]:
description = trophy["data"]["description"]
def main():
"""Provide the program's entry point when directly executed."""
if len(sys.argv) != 2:
print("Usage: {} USERNAME".format(sys.argv[0]))
return 1
authenticator = prawcore.TrustedAuthenticator(
prawcore.Requestor("prawcore_read_only_example"),
os.environ["PRAWCORE_CLIENT_ID"],
os.environ["PRAWCORE_CLIENT_SECRET"],
)
authorizer = prawcore.ReadOnlyAuthorizer(authenticator)
authorizer.refresh()
user = sys.argv[1]
with prawcore.session(authorizer) as session:
data = session.request("GET", "/api/v1/user/{}/trophies".format(user))
for trophy in data["data"]["trophies"]:
description = trophy["data"]["description"]
print(
trophy["data"]["name"]
+ (" ({})".format(description) if description else "")