Skip to content

Instantly share code, notes, and snippets.

@jvanasco
Created August 10, 2015 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvanasco/d723b592b7ace14e9b30 to your computer and use it in GitHub Desktop.
Save jvanasco/d723b592b7ace14e9b30 to your computer and use it in GitHub Desktop.
consolidated oauth1 object Interfaces used by oauthlib and flask-oauthlib
"""This explains some object interfaces used in validator.py
"""
class _DatabaseObject(object):
pass
class _Relationship(object):
pass
class _Timestamp(object):
pass
# ------------------------------------------------------------------------------
class AccessToken(_DatabaseObject):
"""
An AccessToken is a database object.
REQUIRED Attributes:
* oauth_token - STRING
* oauth_token_secret - STRING
* realms - LIST
* client - RELATIONSHIP
* user - RELATIONSHIP
Recommended Attributes:
* token_type - STRING (i.e. "bearer")
* oauth_version - STRING (i.e. "1")
* timestamp_created - TIMESTAMP
More info:
* When created in the `access_token_setter` a ``client`` is available via `request.client`
* When created in the `access_token_setter` a ``user`` is available via looking up the active ``request.verifier``
"""
# required
oauth_token = ''
oauth_token_secret = ''
realms = []
client = _Relationship()
user = _Relationship()
# recommended
token_type = 'bearer'
oauth_version = '1'
timestamp_created = _Timestamp()
class RequestToken(_DatabaseObject):
"""
A RequestToken is a database object.
REQUIRED Attributes:
* oauth_token - STRING
* oauth_token_secret - STRING
* oauth_callback_confirmed - STRING (true, false)
* realms - LIST
* client - RELATIONSHIP
* user - RELATIONSHIP
Recommended Attributes:
* oauth_version - STRING (i.e. "1")
* timestamp_created - TIMESTAMP
* timestamp_expires - TIMESTAMP
More info:
when created in the `access_token_setter` a ``client`` is available via `request.client`
"""
# required
oauth_token = ''
oauth_token_secret = ''
oauth_callback_confirmed = ''
realms = []
client = _Relationship()
user = _Relationship()
# recommended
oauth_version = '1'
timestamp_created = _Timestamp()
timestamp_expires = _Timestamp()
class Client(object):
"""
REQUIRED Attributes:
* client_key - STRING unique to the client
* client_secret - STRING used for signing
* redirect_uris - LIST
* default_realms - LIST
Recommended Attributes:
* default_redirect_uri
"""
# required
client_key = ''
client_secret = ''
redirect_uris = []
default_realms = []
# recommended
default_redirect_uri = ''
class Token(object):
id = None
client_id = None
user_id = None
token_type = 'bearer'
access_token = None
refresh_token = None
expires = None
realms = None
# ------------------------------------------------------------------------------
class AccessTokenDict(dict):
"""
* ``oauth_token`` the access token string.
* ``oauth_token_secret`` the token specific secret used in signing.
* ``oauth_authorized_realms`` a space separated list of realms.
Used by:
* RequestValidator.save_access_token
"""
def __init__(self,
oauth_token = '',
oauth_token_secret = '',
oauth_authorized_realms = '',
):
self['oauth_token'] = oauth_token
self['oauth_token_secret'] = oauth_token_secret
self['oauth_authorized_realms'] = oauth_authorized_realms
class RequestTokenDict(dict):
"""
* ``oauth_token`` the request token string.
* ``oauth_token_secret`` the token specific secret used in signing.
* ``oauth_callback_confirmed`` the string ``true``.
Used by:
* RequestTokenEndpoint.create_request_token
* RequestValidator.save_request_token
"""
def __init__(self,
oauth_token = '',
oauth_token_secret = '',
oauth_callback_confirmed = '',
):
self['oauth_token'] = oauth_token
self['oauth_token_secret'] = oauth_token_secret
self['oauth_callback_confirmed'] = oauth_callback_confirmed
class VerifierDict(dict):
"""
* ``oauth_verifier``
* ``oauth_token``
Used by:
* RequestValidator.save_verifier
"""
def __init__(self,
oauth_verifier = '',
oauth_token = '',
):
self['oauth_verifier'] = oauth_token
self['oauth_token'] = oauth_token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment