Skip to content

Commit

Permalink
Add Reddit.auth containing an implicit method.
Browse files Browse the repository at this point in the history
  • Loading branch information
bboe committed Aug 8, 2016
1 parent 63a5c46 commit 9ac5b46
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions praw/models/__init__.py
@@ -1,5 +1,5 @@
"""Provide the PRAW models."""

from .auth import Auth # NOQA
from .front import Front # NOQA
from .helpers import LiveHelper, MultiredditHelper, SubredditHelper # NOQA
from .inbox import Inbox # NOQA
Expand All @@ -19,7 +19,7 @@
from .subreddits import Subreddits # NOQA
from .user import User # NOQA

__all__ = ('Comment', 'Front', 'Inbox', 'Listing', 'ListingGenerator',
__all__ = ('Auth', 'Comment', 'Front', 'Inbox', 'Listing', 'ListingGenerator',
'LiveHelper', 'LiveThread', 'Message', 'ModAction', 'MoreComments',
'Multireddit', 'MultiredditHelper', 'Redditor', 'RedditorList',
'Submission', 'Subreddit', 'SubredditHelper', 'SubredditMessage',
Expand Down
33 changes: 33 additions & 0 deletions praw/models/auth.py
@@ -0,0 +1,33 @@
"""Provide the Auth class."""
from prawcore import ImplicitAuthorizer, UntrustedAuthenticator, session

from .base import PRAWBase
from ..exceptions import ClientException


class Auth(PRAWBase):
"""Auth provides an interface to Reddit's authorization."""

def implicit(self, access_token, expires_in, scope):
"""Set the active authorization to be an implicit authorization.
:param access_token: The access_token obtained from Reddit's callback.
:param expires_in: The number of seconds the ``access_token`` is valid
for. The origin of this value was returned from Reddit's callback.
You may need to subtract an offset before passing in this number to
account for a delay between when Reddit prepared the response, and
when you make this function call.
:param scope: A space-delimited string of Reddit OAuth2 scope names as
returned from Reddit's callback.
Raise ``ClientException`` if ``Reddit`` was initialized for a
non-installed application type.
"""
authenticator = self._reddit._read_only_core._authenticator
if not isinstance(UntrustedAuthenticator, authenticator):
raise ClientException('implicit can only be used with installed '
'apps.')
implicit_session = session(ImplicitAuthorizer(
authenticator, access_token, expires_in, scope))
self._reddit._core = self._reddit._authorized_core = implicit_session
3 changes: 3 additions & 0 deletions praw/reddit.py
Expand Up @@ -102,6 +102,9 @@ def __init__(self, site_name=None, **config_settings):
self._prepare_objector()
self._prepare_prawcore()

#: An instance of :class:`.Auth`.
self.auth = models.Auth(self, None)

#: An instance of :class:`.Front`.
self.front = models.Front(self)

Expand Down

0 comments on commit 9ac5b46

Please sign in to comment.