|
4 | 4 | from functools import wraps |
5 | 5 | from time import strftime |
6 | 6 |
|
| 7 | +from django.contrib.auth import get_user_model |
7 | 8 | from django.contrib.auth.views import redirect_to_login |
8 | 9 | from django.http import JsonResponse |
9 | 10 | from django.http.response import HttpResponse, HttpResponseBadRequest |
10 | 11 | from django.template.response import TemplateResponse |
| 12 | +from django.core.exceptions import ObjectDoesNotExist |
11 | 13 | from django.utils.decorators import method_decorator |
12 | 14 | from django.views.decorators.csrf import csrf_exempt |
13 | 15 | from django.views.decorators.debug import sensitive_post_parameters |
|
20 | 22 | from oauth2_provider.views.introspect import ( |
21 | 23 | IntrospectTokenView as DotIntrospectTokenView, |
22 | 24 | ) |
23 | | -from waffle import switch_is_active |
| 25 | +from waffle import switch_is_active, get_waffle_flag_model |
24 | 26 | from oauth2_provider.models import get_application_model |
25 | 27 | from oauthlib.oauth2 import AccessDeniedError |
26 | 28 | from oauthlib.oauth2.rfc6749.errors import InvalidClientError, InvalidGrantError, InvalidRequestError |
@@ -102,6 +104,19 @@ def _has_param(self, request, key): |
102 | 104 | def _check_for_required_params(self, request): |
103 | 105 | missing_params = [] |
104 | 106 | v3 = True if request.path.startswith('/v3/o/authorize') else False |
| 107 | + flag = get_waffle_flag_model().get("v3_early_adopter") |
| 108 | + req_meta = request.META |
| 109 | + url_query = parse_qs(req_meta.get('QUERY_STRING')) |
| 110 | + client_id = url_query.get('client_id', [None]) |
| 111 | + try: |
| 112 | + app = get_application_model().objects.get(client_id=client_id[0]) |
| 113 | + application_user = get_user_model().objects.get(id=app.user_id) |
| 114 | + if flag.id is not None and flag.is_active_for_user(application_user): |
| 115 | + print("flag is active for this user") |
| 116 | + else: |
| 117 | + print("flag is not active for this user") |
| 118 | + except ObjectDoesNotExist: |
| 119 | + print("object not found") |
105 | 120 |
|
106 | 121 | if switch_is_active('require_pkce'): |
107 | 122 | if not request.GET.get('code_challenge', None): |
|
0 commit comments