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_refresh__with_invalid_username_or_password(self):
authorizer = prawcore.ScriptAuthorizer(
self.authentication, USERNAME, "invalidpassword"
)
with Betamax(REQUESTOR).use_cassette(
"ScriptAuthorizer_refresh__with_invalid_username_or_password"
):
self.assertRaises(prawcore.OAuthException, authorizer.refresh)
self.assertFalse(authorizer.is_valid())
def test_initialize__with_untrusted_authenticator(self):
authenticator = prawcore.UntrustedAuthenticator(REQUESTOR, CLIENT_ID)
self.assertRaises(
prawcore.InvalidInvocation,
prawcore.ScriptAuthorizer,
authenticator,
None,
None,
)
def script_authorizer():
authenticator = prawcore.TrustedAuthenticator(
REQUESTOR, CLIENT_ID, CLIENT_SECRET
)
authorizer = prawcore.ScriptAuthorizer(authenticator, USERNAME, PASSWORD)
authorizer.refresh()
return authorizer
def main():
"""Provide the program's entry point when directly executed."""
authenticator = prawcore.TrustedAuthenticator(
prawcore.Requestor("prawcore_script_auth_example"),
os.environ["PRAWCORE_CLIENT_ID"],
os.environ["PRAWCORE_CLIENT_SECRET"],
)
authorizer = prawcore.ScriptAuthorizer(
authenticator,
os.environ["PRAWCORE_USERNAME"],
os.environ["PRAWCORE_PASSWORD"],
)
authorizer.refresh()
with prawcore.session(authorizer) as session:
data = session.request("GET", "/api/v1/me/friends")
for friend in data["data"]["children"]:
print(friend["name"])
return 0
def _prepare_trusted_prawcore(self, requestor):
authenticator = TrustedAuthenticator(
requestor,
self.config.client_id,
self.config.client_secret,
self.config.redirect_uri,
)
read_only_authorizer = ReadOnlyAuthorizer(authenticator)
self._read_only_core = session(read_only_authorizer)
if self.config.username and self.config.password:
script_authorizer = ScriptAuthorizer(
authenticator, self.config.username, self.config.password
)
self._core = self._authorized_core = session(script_authorizer)
elif self.config.refresh_token:
authorizer = Authorizer(authenticator, self.config.refresh_token)
self._core = self._authorized_core = session(authorizer)
else:
self._core = self._read_only_core