Replace django redirect with custom HttpResponse object.

This commit is contained in:
juanifioren 2015-11-12 17:12:18 -03:00
parent 2d1e246b2c
commit 8b0d869f7b
2 changed files with 17 additions and 6 deletions

View file

@ -1,9 +1,19 @@
from django.conf import settings as django_settings from django.conf import settings as django_settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.http import HttpResponse
from oidc_provider import settings from oidc_provider import settings
def redirect(uri):
"""
Custom Response object for redirecting to a Non-HTTP url scheme.
"""
response = HttpResponse('', status=302)
response['Location'] = uri
return response
def get_issuer(): def get_issuer():
""" """
Construct the issuer full url. Basically is the site url with some path Construct the issuer full url. Basically is the site url with some path

View file

@ -3,7 +3,7 @@ import logging
from Crypto.PublicKey import RSA from Crypto.PublicKey import RSA
from django.contrib.auth.views import redirect_to_login, logout from django.contrib.auth.views import redirect_to_login, logout
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse from django.http import JsonResponse
from django.shortcuts import render from django.shortcuts import render
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.views.decorators.http import require_http_methods from django.views.decorators.http import require_http_methods
@ -15,7 +15,7 @@ from oidc_provider.lib.endpoints.authorize import *
from oidc_provider.lib.endpoints.token import * from oidc_provider.lib.endpoints.token import *
from oidc_provider.lib.endpoints.userinfo import * from oidc_provider.lib.endpoints.userinfo import *
from oidc_provider.lib.errors import * from oidc_provider.lib.errors import *
from oidc_provider.lib.utils.common import get_issuer, get_rsa_key from oidc_provider.lib.utils.common import redirect, get_issuer, get_rsa_key
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -42,7 +42,7 @@ class AuthorizeView(View):
# Check if user previously give consent. # Check if user previously give consent.
if authorize.client_has_user_consent(): if authorize.client_has_user_consent():
uri = authorize.create_response_uri() uri = authorize.create_response_uri()
return HttpResponseRedirect(uri) return redirect(uri)
# Generate hidden inputs for the form. # Generate hidden inputs for the form.
context = { context = {
@ -79,7 +79,7 @@ class AuthorizeView(View):
authorize.params.redirect_uri, authorize.params.redirect_uri,
authorize.params.state) authorize.params.state)
return HttpResponseRedirect(uri) return redirect(uri)
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
@ -99,14 +99,15 @@ class AuthorizeView(View):
authorize.set_client_user_consent() authorize.set_client_user_consent()
uri = authorize.create_response_uri() uri = authorize.create_response_uri()
return HttpResponseRedirect(uri)
return redirect(uri)
except (AuthorizeError) as error: except (AuthorizeError) as error:
uri = error.create_uri( uri = error.create_uri(
authorize.params.redirect_uri, authorize.params.redirect_uri,
authorize.params.state) authorize.params.state)
return HttpResponseRedirect(uri) return redirect(uri)
class TokenView(View): class TokenView(View):