mirror of
https://github.com/yawaflua/Flask-Discord.git
synced 2025-12-10 04:19:31 +02:00
Add requires_authorization utility
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
from .client import DiscordOAuth2Session
|
||||
|
||||
from .exceptions import *
|
||||
from .utils import *
|
||||
|
||||
from .client import DiscordOAuth2Session
|
||||
|
||||
|
||||
__all__ = [
|
||||
"DiscordOAuth2Session",
|
||||
"requires_authorization",
|
||||
|
||||
"HttpException",
|
||||
"Unauthorized",
|
||||
]
|
||||
|
||||
|
||||
__version__ = "0.1.10"
|
||||
__version__ = "0.1.11"
|
||||
|
||||
24
flask_discord/utils.py
Normal file
24
flask_discord/utils.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""Few utility functions and decorators."""
|
||||
import functools
|
||||
|
||||
from . import exceptions
|
||||
from flask import current_app
|
||||
|
||||
|
||||
# Decorators.
|
||||
|
||||
def requires_authorization(view):
|
||||
"""A decorator for flask views which raises exception :py:class:`flask_discord.exceptions.Unauthorized` if the user
|
||||
is not authorized from Discord OAuth2.
|
||||
|
||||
"""
|
||||
|
||||
# TODO: Add support to validate scopes.
|
||||
|
||||
@functools.wraps(view)
|
||||
def wrapper(*args, **kwargs):
|
||||
if not current_app.discord.authorized:
|
||||
raise exceptions.Unauthorized
|
||||
return view(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
Reference in New Issue
Block a user