How to use the prawcore.TrustedAuthenticator 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__fail_with_implicit(self):
        authenticator = prawcore.TrustedAuthenticator(
            REQUESTOR, CLIENT_ID, CLIENT_SECRET, REDIRECT_URI
        )
        self.assertRaises(
            prawcore.InvalidInvocation,
            authenticator.authorize_url,
            "temporary",
            ["identity", "read"],
            "a_state",
            implicit=True,
        )
github praw-dev / prawcore / tests / test_authenticator.py View on Github external
def test_authorize_url(self):
        authenticator = prawcore.TrustedAuthenticator(
            REQUESTOR, CLIENT_ID, CLIENT_SECRET, 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_authenticator.py View on Github external
def test_revoke_token__with_refresh_token_hint(self):
        authenticator = prawcore.TrustedAuthenticator(
            REQUESTOR, CLIENT_ID, CLIENT_SECRET
        )
        with Betamax(REQUESTOR).use_cassette(
            "TrustedAuthenticator_revoke_token__with_refresh_token_hint"
        ):
            authenticator.revoke_token("dummy token", "refresh_token")
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 / tests / test_authorizer.py View on Github external
def setUp(self):
        self.authentication = prawcore.TrustedAuthenticator(
            REQUESTOR, CLIENT_ID, CLIENT_SECRET
        )
github praw-dev / prawcore / tests / test_sessions.py View on Github external
def __init__(self):
        super(InvalidAuthorizer, self).__init__(
            prawcore.TrustedAuthenticator(REQUESTOR, CLIENT_ID, CLIENT_SECRET)
        )
github praw-dev / prawcore / tests / test_authenticator.py View on Github external
def test_revoke_token(self):
        authenticator = prawcore.TrustedAuthenticator(
            REQUESTOR, CLIENT_ID, CLIENT_SECRET
        )
        with Betamax(REQUESTOR).use_cassette(
            "TrustedAuthenticator_revoke_token"
        ):
            authenticator.revoke_token("dummy token")
github praw-dev / prawcore / examples / obtain_refresh_token.py View on Github external
def main():
    """Provide the program's entry point when directly executed."""
    if len(sys.argv) < 2:
        print("Usage: {} SCOPE...".format(sys.argv[0]))
        return 1

    authenticator = prawcore.TrustedAuthenticator(
        prawcore.Requestor("prawcore_refresh_token_example"),
        os.environ["PRAWCORE_CLIENT_ID"],
        os.environ["PRAWCORE_CLIENT_SECRET"],
        os.environ["PRAWCORE_REDIRECT_URI"],
    )

    state = str(random.randint(0, 65000))
    url = authenticator.authorize_url("permanent", sys.argv[1:], state)
    print(url)

    client = receive_connection()
    data = client.recv(1024).decode("utf-8")
    param_tokens = data.split(" ", 2)[1].split("?", 1)[1].split("&")
    params = {
        key: value
        for (key, value) in [token.split("=") for token in param_tokens]
github praw-dev / prawcore / examples / caching_requestor.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

    caching_requestor = prawcore.Requestor(
        "prawcore_device_id_auth_example", session=CachingSession()
    )
    authenticator = prawcore.TrustedAuthenticator(
        caching_requestor,
        os.environ["PRAWCORE_CLIENT_ID"],
        os.environ["PRAWCORE_CLIENT_SECRET"],
    )
    authorizer = prawcore.ReadOnlyAuthorizer(authenticator)
    authorizer.refresh()

    user = sys.argv[1]
    with prawcore.session(authorizer) as session:
        data1 = session.request("GET", "/api/v1/user/{}/trophies".format(user))

    with prawcore.session(authorizer) as session:
        data2 = session.request("GET", "/api/v1/user/{}/trophies".format(user))

    for trophy in data1["data"]["trophies"]:
        description = trophy["data"]["description"]
github praw-dev / prawcore / examples / read_only_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.TrustedAuthenticator(
        prawcore.Requestor("prawcore_read_only_example"),
        os.environ["PRAWCORE_CLIENT_ID"],
        os.environ["PRAWCORE_CLIENT_SECRET"],
    )
    authorizer = prawcore.ReadOnlyAuthorizer(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 "")