@@ -37,35 +37,39 @@ And you can also modify the response with after_request::
37
37
Bindings
38
38
--------
39
39
40
+ .. versionchanged :: 0.4
41
+
42
+ .. module :: flask_oauthlib.contrib.oauth2
43
+
40
44
Bindings are objects you can use to configure flask-oauthlib for use with
41
45
various data stores. They allow you to define the required getters and setters
42
46
for each data store with little effort.
43
47
44
48
SQLAlchemy OAuth2
45
49
`````````````````
46
50
47
- :class: ` SQLAlchemyBinding ` sets up getters and setters for storing the user,
51
+ :meth: ` bind_sqlalchemy ` sets up getters and setters for storing the user,
48
52
client, token and grant with SQLAlchemy, with some sane defaults. To use this
49
53
class you'll need to create a SQLAlchemy model for each object. You can find
50
54
examples of how to setup your SQLAlchemy models here: ref:`oauth2 `.
51
55
52
56
You'll also need to provide another function which returns the currently
53
57
logged-in user.
54
58
55
- An example of how to use :class: ` SQLAlchemyBinding `::
59
+ An example of how to use :meth: ` bind_sqlalchemy `::
56
60
57
61
oauth = OAuth2Provider(app)
58
62
59
- SQLAlchemyBinding (oauth, db.session, user=User, client=Client,
60
- token=Token, grant=Grant, current_user=current_user)
63
+ bind_sqlalchemy (oauth, db.session, user=User, client=Client,
64
+ token=Token, grant=Grant, current_user=current_user)
61
65
62
66
Any of the classes can be omitted if you wish to register the getters and
63
67
setters yourself::
64
68
65
69
oauth = OAuth2Provider(app)
66
70
67
- SQLAlchemyBinding (oauth, db.session, user=User, client=Client,
68
- token=Token)
71
+ bind_sqlalchemy (oauth, db.session, user=User, client=Client,
72
+ token=Token)
69
73
70
74
@oauth.grantgetter
71
75
def get_grant(client_id, code):
@@ -92,49 +96,22 @@ Grant Cache
92
96
93
97
Since the life of a Grant token is very short (usually about 100 seconds),
94
98
storing it in a relational database is inefficient.
95
- The :class: ` GrantCacheBinding ` allows you to more efficiently cache the grant
99
+ The :meth: ` bind_cache_grant ` allows you to more efficiently cache the grant
96
100
token using Memcache, Redis, or some other caching system.
97
101
98
102
An example::
99
103
100
104
oauth = OAuth2Provider(app)
101
- config = {'OAUTH2_CACHE_TYPE': 'redis'}
105
+ app. config.update( {'OAUTH2_CACHE_TYPE': 'redis'})
102
106
103
- GrantCacheBinding (app, oauth, current_user, config=config )
107
+ bind_cache_grant (app, oauth, current_user)
104
108
105
109
- `app `: flask application
106
110
- `oauth `: OAuth2Provider instance
107
111
- `current_user `: a function that returns the current user
108
- - `config `: Any extra configuration
109
112
110
- The configuration options are described below. The :class: ` GrantCacheBinding `
113
+ The configuration options are described below. The :meth: ` bind_cache_grant `
111
114
will use the configuration options from `Flask-Cache ` if they are set, else it
112
115
will set them to the following defaults. Any configuration specific to
113
- :class: ` GrantCacheBinding ` will take precedence over any `Flask-Cache `
116
+ :meth: ` bind_cache_grant ` will take precedence over any `Flask-Cache `
114
117
configuration that has been set.
115
-
116
- +------------------------------------+-------------------------------------------------------------------------------------------------------------------+-------------------------+-------------+
117
- | **Option ** | **Description ** | **Flask-Cache Default ** | **Default ** |
118
- +------------------------------------+-------------------------------------------------------------------------------------------------------------------+-------------------------+-------------+
119
- | **OAUTH2_CACHE_DEFAULT_TIMEOUT ** | The default timeout that is used. A grant token expires after this length of time. | CACHE_DEFAULT_TIMEOUT | 100s |
120
- +------------------------------------+-------------------------------------------------------------------------------------------------------------------+-------------------------+-------------+
121
- | **OAUTH2_CACHE_THRESHOLD ** | The maximum number of items the cache stores before it starts deleting some | CACHE_THRESHOLD | 500s |
122
- +------------------------------------+-------------------------------------------------------------------------------------------------------------------+-------------------------+-------------+
123
- | **OAUTH2_CACHE_KEY_PREFIX ** | A prefix that is added before all keys | CACHE_KEY_PREFIX | None |
124
- +------------------------------------+-------------------------------------------------------------------------------------------------------------------+-------------------------+-------------+
125
- | **OAUTH2_CACHE_MEMCACHED_SERVERS ** | A list or tuple of server addresses or alternatively a :class: `memcache.Client ` or a compatible client | CACHE_MEMCACHED_SERVERS | None |
126
- +------------------------------------+-------------------------------------------------------------------------------------------------------------------+-------------------------+-------------+
127
- | **OAUTH2_CACHE_REDIS_HOST ** | Address of the Redis server or an object which API is compatible with the official Python Redis client (redis-py) | CACHE_REDIS_HOST | localhost |
128
- +------------------------------------+-------------------------------------------------------------------------------------------------------------------+-------------------------+-------------+
129
- | **OAUTH2_CACHE_REDIS_PORT ** | Port number on which Redis server listens for connections | CACHE_REDIS_PORT | 6379 |
130
- +------------------------------------+-------------------------------------------------------------------------------------------------------------------+-------------------------+-------------+
131
- | **OAUTH2_CACHE_REDIS_PASSWORD ** | Password authentication for the Redis server | CACHE_REDIS_PASSWORD | None |
132
- +------------------------------------+-------------------------------------------------------------------------------------------------------------------+-------------------------+-------------+
133
- | **OAUTH2_CACHE_REDIS_DB ** | Database (zero-based numeric index) on Redis Server to connect | CACHE_REDIS_DB | 0 |
134
- +------------------------------------+-------------------------------------------------------------------------------------------------------------------+-------------------------+-------------+
135
- | **OAUTH2_CACHE_DIR ** | The directory where cache files are stored | CACHE_DIR | None |
136
- +------------------------------------+-------------------------------------------------------------------------------------------------------------------+-------------------------+-------------+
137
- | **OAUTH2_CACHE_MODE ** | The file mode wanted for the cache files | CACHE_MODE | 0600 |
138
- +------------------------------------+-------------------------------------------------------------------------------------------------------------------+-------------------------+-------------+
139
- | **OAUTH2_CACHE_TYPE ** | The cache system to be used (null, simple, redis, memcache, filesystem) | CACHE_TYPE | null |
140
- +------------------------------------+-------------------------------------------------------------------------------------------------------------------+-------------------------+-------------+
0 commit comments