Opened 3 months ago

Closed 3 months ago

#35188 closed Bug (invalid)

Redirect URI Mismatch with Box API

Reported by: Arnautt Owned by: nobody
Component: contrib.auth Version: 5.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When attempting to authenticate with the Box API, user encounter a "redirect_uri_mismatch" error. Here are the steps to reproduce :

  • Create the minimal example to reproduce the error
  1. settings.py
BOX_CLIENT_ID = 'YOUR_BOX_CLIENT_ID'
BOX_CLIENT_SECRET = 'YOUR_BOX_CLIENT_SECRET'
  1. views.py
from django.shortcuts import redirect
from django.conf import settings
from boxsdk import OAuth2

def authenticate_with_box(request):
    oauth = OAuth2(
        client_id=settings.BOX_CLIENT_ID,
        client_secret=settings.BOX_CLIENT_SECRET,
    )
    auth_url, csrf_token = oauth.get_authorization_url(redirect_url=request.build_absolute_uri(reverse('upload')))
    request.session['csrf_token'] = csrf_token
    return redirect(auth_url)

def upload(request):
    return render(request, "upload.html", {'access_token': request.session["access_token"]})

  1. urls.py
from django.urls import path
from .views import authenticate_with_box

urlpatterns = [
    path('', authenticate_with_box, name='authenticate_with_box'),
    path('upload/', views.upload, name='upload'),
]
  • Run the server
python manage.py runserver

Change History (1)

comment:1 by David Sanders, 3 months ago

Resolution: invalid
Status: newclosed

Trac is not a support request channel. If you need help setting up Django you can get help from a friendly community member in one of the official support channels: https://www.djangoproject.com/community/ ☺️

Note: See TracTickets for help on using tickets.
Back to Top