<commit_before>import base64

from time import time
from datetime import datetime

from django.conf import settings
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from django.utils.translation import ugettext_lazy as _

from oauthost.models import Client, AuthorizationCode, Token
from oauthost.utils import *
from oauthost.config import *


@login_required
def endpoint_authorize(request):
    """
    SPEC: The authorization endpoint is used to interact with the resource
    owner and obtain an authorization grant.

    SPEC: The authorization server MUST support TLS...
    The authorization server MUST support the use of the HTTP "GET" method [RFC2616]
    for the authorization endpoint, and MAY support the use of the "POST" method as well.

    """

    # SPEC: Since requests to the authorization endpoint result in user authentication
    # and the transmission of clear-text credentials (in the HTTP response),
    # the authorization server MUST require the use of a transport-layer
    # security mechanism when sending requests to the authorization endpoint.
    if not request.is_secure() and not settings.DEBUG:
        # Insecure connections are only available in debug mode.
        return ep_auth_response_error_page(request, _('OAuth requires secure connection.'), 403)

    if request.POST.get('auth_decision') is None:
        # User has made no decision on auth confirmation yet.

        input_params = filter_input_params(request.REQUEST)

        response_type = input_params.get('response_type')
        client_id = input_params.get('client_id')

        redirect_uri = input_params.get('redirect_uri')
        redirect_uri_final = redirect_uri

        if client_id is None:
            # Fail fast without a DB hit.<commit_msg>Added auth session flush into endpoint_authorize.<commit_after>import base64

from time import time
from datetime import datetime

from django.conf import settings
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth import SESSION_KEY
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from django.utils.translation import ugettext_lazy as _

from oauthost.models import Client, AuthorizationCode, Token
from oauthost.utils import *
from oauthost.config import *


@login_required
def endpoint_authorize(request):
    """
    SPEC: The authorization endpoint is used to interact with the resource
    owner and obtain an authorization grant.

    SPEC: The authorization server MUST support TLS...
    The authorization server MUST support the use of the HTTP "GET" method [RFC2616]
    for the authorization endpoint, and MAY support the use of the "POST" method as well.

    """

    # Avoid usage of previous auth sessions.
    request.session[SESSION_KEY] = None

    # SPEC: Since requests to the authorization endpoint result in user authentication
    # and the transmission of clear-text credentials (in the HTTP response),
    # the authorization server MUST require the use of a transport-layer
    # security mechanism when sending requests to the authorization endpoint.
    if not request.is_secure() and not settings.DEBUG:
        # Insecure connections are only available in debug mode.
        return ep_auth_response_error_page(request, _('OAuth requires secure connection.'), 403)

    if request.POST.get('auth_decision') is None:
        # User has made no decision on auth confirmation yet.

        input_params = filter_input_params(request.REQUEST)

        response_type = input_params.get('response_type')
        client_id = input_params.get('client_id')

        redirect_uri = input_params.get('redirect_uri')
        redirect_uri_final = redirect_uri

        if client_id is None:
            # Fail fast without a DB hit.
{'fraction_non_alphanumeric': 0.05664541441883276, 'fraction_numerical': 0.004413928396272682, 'mean_word_length': 3.855952380952381, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4402912', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1007, 'n_words': 416}