How to use the prawcore.DeviceIDAuthorizer 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_short_device_id(self):
        authorizer = prawcore.DeviceIDAuthorizer(self.authentication, "a" * 19)
        with Betamax(REQUESTOR).use_cassette(
            "DeviceIDAuthorizer_refresh__with_short_device_id"
        ):
            self.assertRaises(prawcore.OAuthException, authorizer.refresh)
github praw-dev / prawcore / tests / test_sessions.py View on Github external
def test_init__with_device_id_authorizer(self):
        authenticator = prawcore.UntrustedAuthenticator(REQUESTOR, CLIENT_ID)
        authorizer = prawcore.DeviceIDAuthorizer(authenticator)
        prawcore.Session(authorizer)
github praw-dev / prawcore / tests / test_authorizer.py View on Github external
def test_initialize(self):
        authorizer = prawcore.DeviceIDAuthorizer(self.authentication)
        self.assertIsNone(authorizer.access_token)
        self.assertIsNone(authorizer.scopes)
        self.assertFalse(authorizer.is_valid())
github praw-dev / prawcore / tests / test_authorizer.py View on Github external
def test_initialize__with_trusted_authenticator(self):
        authenticator = prawcore.TrustedAuthenticator(None, None, None)
        self.assertRaises(
            prawcore.InvalidInvocation,
            prawcore.DeviceIDAuthorizer,
            authenticator,
        )
github praw-dev / prawcore / examples / device_id_auth_trophies.py View on Github external
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.UntrustedAuthenticator(
        prawcore.Requestor("prawcore_device_id_auth_example"),
        os.environ["PRAWCORE_CLIENT_ID"],
    )
    authorizer = prawcore.DeviceIDAuthorizer(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 "")
        )

    return 0
github praw-dev / praw / praw / reddit.py View on Github external
def _prepare_untrusted_prawcore(self, requestor):
        authenticator = UntrustedAuthenticator(
            requestor, self.config.client_id, self.config.redirect_uri
        )
        read_only_authorizer = DeviceIDAuthorizer(authenticator)
        self._read_only_core = session(read_only_authorizer)
        if 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