How to use the prawcore.ScriptAuthorizer function in prawcore

To help you get started, we’ve selected a few prawcore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github praw-dev / prawcore / tests / test_authorizer.py View on Github external
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())
github praw-dev / prawcore / tests / test_authorizer.py View on Github external
def test_initialize__with_untrusted_authenticator(self):
        authenticator = prawcore.UntrustedAuthenticator(REQUESTOR, CLIENT_ID)
        self.assertRaises(
            prawcore.InvalidInvocation,
            prawcore.ScriptAuthorizer,
            authenticator,
            None,
            None,
        )
github praw-dev / prawcore / tests / test_sessions.py View on Github external
def script_authorizer():
    authenticator = prawcore.TrustedAuthenticator(
        REQUESTOR, CLIENT_ID, CLIENT_SECRET
    )
    authorizer = prawcore.ScriptAuthorizer(authenticator, USERNAME, PASSWORD)
    authorizer.refresh()
    return authorizer
github praw-dev / prawcore / examples / script_auth_friend_list.py View on Github external
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
github praw-dev / praw / praw / reddit.py View on Github external
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