Returns a endpoint that handles OAuth authorization requests.


  The template described by ``authorization_template_name`` is rendered with a
  Django ``RequestContext`` with the following variables:

  * ``form``: a Django ``Form`` that may hold data internal to the ``djoauth2``
    application.
  * ``client``: The :py:class:`djoauth2.models.Client` requesting access to the
    user's scopes.
  * ``scopes``: A list of :py:class:`djoauth2.models.Scope`, one for each of
    the scopes requested by the client.
  * ``form_action``: The URI to which the form should be submitted -- use this
    value in the ``action=""`` attribute on a ``<form>`` element.

  :param missing_redirect_uri: a string, the URI to which to redirect the user
      when the request is made by a client without a valid redirect URI.

  :param authorization_endpoint_uri: a string, the URI of this endpoint. Used
      by the authorization form so that the form is submitted to this same
      endpoint.

  :param authorization_template_name: a string, the name of the template to
      render when handling authorization requests.

  :rtype: A view function endpoint.

def make_authorization_endpoint(missing_redirect_uri,
                                authorization_endpoint_uri,
                                authorization_template_name):
  """ Returns a endpoint that handles OAuth authorization requests.


  The template described by ``authorization_template_name`` is rendered with a
  Django ``RequestContext`` with the following variables:

  * ``form``: a Django ``Form`` that may hold data internal to the ``djoauth2``
    application.
  * ``client``: The :py:class:`djoauth2.models.Client` requesting access to the
    user's scopes.
  * ``scopes``: A list of :py:class:`djoauth2.models.Scope`, one for each of
    the scopes requested by the client.
  * ``form_action``: The URI to which the form should be submitted -- use this
    value in the ``action=""`` attribute on a ``<form>`` element.

  :param missing_redirect_uri: a string, the URI to which to redirect the user
      when the request is made by a client without a valid redirect URI.

  :param authorization_endpoint_uri: a string, the URI of this endpoint. Used
      by the authorization form so that the form is submitted to this same
      endpoint.

  :param authorization_template_name: a string, the name of the template to
      render when handling authorization requests.

  :rtype: A view function endpoint.
  """
  @login_required
  @require_http_methods(['GET', 'POST'])
  def authorization_endpoint(request):
    auth_code_generator = AuthorizationCodeGenerator(missing_redirect_uri)

    try:
      auth_code_generator.validate(request)
    except AuthorizationError as authorization_error:
      return auth_code_generator.make_error_redirect(authorization_error)

    if request.method == 'GET':
      return render(request, authorization_template_name, {
          'form': Form(),
          'client': auth_code_generator.client,
          'scopes': auth_code_generator.valid_scope_objects,
          'form_action': update_parameters(
              authorization_endpoint_uri,
              auth_code_generator.get_request_uri_parameters(as_dict=True)),
        })

    if request.method == 'POST':
      form = Form(request)
      if form.is_valid() and request.POST.get('user_action') == 'Accept':
        return auth_code_generator.make_success_redirect()
      else:
        return auth_code_generator.make_error_redirect()

  return authorization_endpoint