Search code examples
djangodjango-allauth

Using django-allauth and Stack Exchange as a provider, how can I change the redirect_uri in my development environment?


I am attempting to use the the allauth plugin and Stack Exchange as a provider.

I have the following settings:

INSTALLED_APPS = [
    ...
    # The Django sites framework is required
    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.stackexchange',
]

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                ...
                # Required by `allauth` template tags
                'django.core.context_processors.request',
            ],
        },
    },
]

SOCIALACCOUNT_PROVIDERS = { 
    'stackexchange': { 
        'SITE': 'stackoverflow' 
    } 
}

I have a registered app over on Stack Apps and it doesn't use the "Client Side Flow" and I've configured my client id and secret key in the Django Admin panel.

In my development environment, though, how do I force a log in to redirect back to my localhost? Right now, I receive this error:

error description: Cannot return to provided redirect_uri

The documentation says:

For local development you can simply use “localhost” for the OAuth domain.

What does this mean and how do I accomplish it?


Solution

  • Just add the page you want to be redirected to your settings

    #settings.py
    LOGIN_REDIRECT_URL = '/example'