Exemplo n.º 1
0
def script_authorizer():
    authenticator = prawcore.TrustedAuthenticator(
        REQUESTOR, CLIENT_ID, CLIENT_SECRET
    )
    authorizer = prawcore.ScriptAuthorizer(authenticator, USERNAME, PASSWORD)
    authorizer.refresh()
    return authorizer
Exemplo n.º 2
0
 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())
Exemplo n.º 3
0
    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())
Exemplo n.º 4
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
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