Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate built-in Cache system #23

Closed
lepture opened this issue Feb 4, 2018 · 0 comments
Closed

Deprecate built-in Cache system #23

lepture opened this issue Feb 4, 2018 · 0 comments
Assignees
Milestone

Comments

@lepture
Copy link
Owner

lepture commented Feb 4, 2018

Per pallets/werkzeug#1249

Werkzeug is going to deprecate werkzeug.contrib.cache, there is not an easy way to maintain a built-in cache system for Flask. In this case, it is suggested that you pass a cache instance as parameter.

Cache Interface

You need to create your own cache object. A cache interface should contain these methods:

  • .get(key)
  • .delete(key)
  • .set(key, value, timeout=None)

Flask OAuth Client

If you need to support OAuth 1, cache is required. You can pass the cache object when initializing or init_app:

from authlib.flask.client import OAuth

oauth = OAuth(app, cache=cache)

# or initialize lazily
oauth = OAuth()
oauth.init_app(app, cache=cache)

Flask OAuth 1 Server

Cache is used a lot in OAuth 1 provider. Instead of passing cache as a parameter,
you can use the helper functions to register hooks:

from authlib.flask.oauth1 import AuthorizationServer, ResourceProtector
from authlib.flask.cache import (
    register_nonce_hooks,
    register_temporary_credential_hooks,
    create_exists_nonce_func
)

# 1. AuthorizationServer
server = AuthorizationServer(app, Client)
register_nonce_hooks(server, cache)
register_temporary_credential_hooks(server, cache)

# 2. ResourceProtector
require_oauth = ResourceProtector(
    app, Client,
    query_token=query_token,
    exists_nonce=create_exists_nonce_func(cache)
)

Flask OAuth 2 Server

Pass cache instead of Flask app into register_cache_authorization_code:

from authlib.flask.oauth2 import register_cache_authorization_code

register_cache_authorization_code(cache, server, create_access_token)

The built-in cache system will be removed in version 0.7.

@lepture lepture self-assigned this Feb 4, 2018
@lepture lepture added this to the Version 0.5 milestone Feb 5, 2018
@lepture lepture changed the title re-think of cache interface Deprecate built-in Cache system Feb 6, 2018
lepture added a commit that referenced this issue Feb 6, 2018
@lepture lepture closed this as completed Feb 11, 2018
coopfeathy added a commit to coopfeathy/authlib-django that referenced this issue Dec 11, 2022
coopfeathy added a commit to coopfeathy/authlib-django that referenced this issue Dec 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant