def script_authorizer(): authenticator = prawcore.TrustedAuthenticator( REQUESTOR, CLIENT_ID, CLIENT_SECRET ) authorizer = prawcore.ScriptAuthorizer(authenticator, USERNAME, PASSWORD) authorizer.refresh() return authorizer
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_refresh(self): authorizer = prawcore.ScriptAuthorizer(self.authentication, USERNAME, PASSWORD) self.assertIsNone(authorizer.access_token) self.assertIsNone(authorizer.scopes) self.assertFalse(authorizer.is_valid()) with Betamax(REQUESTOR).use_cassette("ScriptAuthorizer_refresh"): authorizer.refresh() self.assertIsNotNone(authorizer.access_token) self.assertEqual(set(["*"]), authorizer.scopes) self.assertTrue(authorizer.is_valid())
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 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