How to use the prawcore.UntrustedAuthenticator 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_authenticator.py View on Github external
def test_authorize_url__token(self):
        authenticator = prawcore.UntrustedAuthenticator(
            REQUESTOR, CLIENT_ID, REDIRECT_URI
        )
        url = authenticator.authorize_url(
            "temporary", ["identity", "read"], "a_state", implicit=True
        )
        self.assertIn("client_id={}".format(CLIENT_ID), url)
        self.assertIn("duration=temporary", url)
        self.assertIn("response_type=token", url)
        self.assertIn("scope=identity+read", url)
        self.assertIn("state=a_state", url)
github praw-dev / prawcore / tests / test_authenticator.py View on Github external
def test_authorize_url__code(self):
        authenticator = prawcore.UntrustedAuthenticator(
            REQUESTOR, CLIENT_ID, REDIRECT_URI
        )
        url = authenticator.authorize_url(
            "permanent", ["identity", "read"], "a_state"
        )
        self.assertIn("client_id={}".format(CLIENT_ID), url)
        self.assertIn("duration=permanent", url)
        self.assertIn("response_type=code", url)
        self.assertIn("scope=identity+read", url)
        self.assertIn("state=a_state", url)
github praw-dev / prawcore / tests / test_authorizer.py View on Github external
def test_initialize__with_untrusted_authenticator(self):
        authenticator = prawcore.UntrustedAuthenticator(None, None)
        authorizer = prawcore.Authorizer(authenticator)
        self.assertIsNone(authorizer.access_token)
        self.assertIsNone(authorizer.scopes)
        self.assertIsNone(authorizer.refresh_token)
        self.assertFalse(authorizer.is_valid())
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_authenticator.py View on Github external
def test_authorize_url__fail_with_token_and_permanent(self):
        authenticator = prawcore.UntrustedAuthenticator(
            REQUESTOR, CLIENT_ID, REDIRECT_URI
        )
        self.assertRaises(
            prawcore.InvalidInvocation,
            authenticator.authorize_url,
            "permanent",
            ["identity", "read"],
            "a_state",
            implicit=True,
        )
github praw-dev / prawcore / tests / test_authorizer.py View on Github external
def test_initialize(self):
        authenticator = prawcore.UntrustedAuthenticator(REQUESTOR, CLIENT_ID)
        authorizer = prawcore.ImplicitAuthorizer(
            authenticator, "fake token", 1, "modposts read"
        )
        self.assertEqual("fake token", authorizer.access_token)
        self.assertEqual({"modposts", "read"}, authorizer.scopes)
        self.assertTrue(authorizer.is_valid())
github praw-dev / prawcore / tests / test_sessions.py View on Github external
def test_init__with_implicit_authorizer(self):
        authenticator = prawcore.UntrustedAuthenticator(REQUESTOR, CLIENT_ID)
        authorizer = prawcore.ImplicitAuthorizer(authenticator, None, 0, "")
        prawcore.Session(authorizer)
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 "")
        )
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