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

Баг авторизации api (приложения) #1223

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions authn/decorators/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@ def api(require_auth=True, scopes=None):
def decorator(view):
@functools.wraps(view)
def wrapper(request, *args, **kwargs):
# try to authorize
# requests on behalf of apps (user == owner, for a simplicity)
service_token = request.headers.get("X-Service-Token") or request.GET.get("service_token")
if service_token:
request.me = user_by_service_token(service_token)

# oauth requests for API
oauth_access_token = request.headers.get("Authorization")
if oauth_access_token:
try:
token = oauth2_token_validator.acquire_token(request, scopes)
except MissingAuthorizationError as ex:
raise ApiAuthRequired(title="Missing OAuth token", message=str(ex))
except OAuth2Error as ex:
raise ApiAuthRequired(title="OAuth token error", message=str(ex))

request.me = token.user

# check auth if needed
if require_auth:
# requests on behalf of apps (user == owner, for a simplicity)
service_token = request.headers.get("X-Service-Token") or request.GET.get("service_token")
if service_token:
request.me = user_by_service_token(service_token)

# oauth requests for API
oauth_access_token = request.headers.get("Authorization")
if oauth_access_token:
try:
token = oauth2_token_validator.acquire_token(request, scopes)
except MissingAuthorizationError as ex:
raise ApiAuthRequired(title="Missing OAuth token", message=str(ex))
except OAuth2Error as ex:
raise ApiAuthRequired(title="OAuth token error", message=str(ex))

request.me = token.user

# this user can also come from other types of auth (e.g. cookies)
if not request.me:
raise ApiAuthRequired()
Expand Down
Loading