tutor icon indicating copy to clipboard operation
tutor copied to clipboard

Mismatching redirect URI.

Open AmsellemJoseph opened this issue 1 year ago • 2 comments

yes

Bug description

When i want to signin in studio, I always get this error:

Error: invalid_request Mismatching redirect URI.

Here is my cms-sso config:

Screenshot 2024-03-05 143846

How to reproduce

Environment

This is in Docker environment Additional context

Thx a lot for your help :)

AmsellemJoseph avatar Mar 05 '24 12:03 AmsellemJoseph

Hi @AmsellemJoseph

We've face the same problem in our OpenEdx environment. We followed this solution to solve the problem.

To implement it into tutor we created a plugin with the following code (I've added comments for clarification):

from tutor import hooks

"""
Modify CMS OAuth configuration to prevent "Error: invalid_request. Mismatching redirect URI" when entering to Studio because Django Oauth Toolkit's request_uri is setted as https and we are trying to access as http.

An initial solution to this issue was to change Django Oauth Toolkit configuration directly in django admin, as suggested here https://discuss.openedx.org/t/error-invalid-request-mismatching-redirect-uri/7552 . But whenever we rebuild images or run "tutor local launch" this config is reseted and the issue reappears.

Changing SOCIAL_AUTH_REDIRECT_IS_HTTPS to True make this patch persistent and remove the need of changing django admin. See https://stackoverflow.com/a/56958260
"""

hooks.Filters.ENV_PATCHES.add_item(
    (
        "openedx-cms-common-settings",
        """
SOCIAL_AUTH_REDIRECT_IS_HTTPS = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PORT', '443')
USE_X_FORWARDED_PROTO = True
USE_X_FORWARDED_PORT = True
"""
    )
)

hooks.Filters.ENV_PATCHES.add_item(
     (
         "openedx-lms-common-settings",
         """
SOCIAL_AUTH_REDIRECT_IS_HTTPS = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PORT', '443')
USE_X_FORWARDED_PROTO = True
USE_X_FORWARDED_PORT = True
"""
     )
 )

yagouam avatar Mar 06 '24 08:03 yagouam

hey @yagouam, Thx for your response. I tried it, but unfortunately, it's always the same result...

AmsellemJoseph avatar Mar 06 '24 09:03 AmsellemJoseph

Tutor does not support CMS urls that are suffixed with a port ("mydomain.com:4437") -- this issue is one of the reasons why.

regisb avatar Mar 26 '24 10:03 regisb