I am trying to run simple Django application. I have already installed simple-sso module in my local app. I tried but not solved. Following images tell us that error is occured when i run localserver.
enter image description here enter image description here
Following code is some of "settings.py":
INSTALLED_APPS = [
'ssoLogin.apps.ssoLoginConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'simple_sso.sso_server',
]
ROOT_URLCONF = 'ssoLogin.urls'
# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
SSO_PRIVATE_KEY='ttVCo7bewsATjEPS7CNHd4tIk1ayyBKb1qbPk5DxWZiK4pvyLZQtnpinjPh6fWr3'
SSO_PUBLIC_KEY='hGtAakAg7Sh3SffSs2obwAAflMuzbbLBUJUHpk6WrFnxhA9b78EHNoTOr0DsDho3'
SSO_SERVER='http://127.0.0.1:8000/server'
I used "simple-sso" module correctly according to documentation. I think everything of config(settings.py) is ok but i don't know urls and views are correct. Anyway this is my configuration in urls.py.
Following code:
from django.contrib import admin
from django.urls import path, include, re_path
from simple_sso.sso_server.server import Server
from simple_sso.sso_client.client import Client
from django.conf import settings
test_client = Client(settings.SSO_SERVER, settings.SSO_PUBLIC_KEY, settings.SSO_PRIVATE_KEY)
test_server = Server()
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
re_path(r'^server/', include(test_server.get_urls())),
re_path(r'^client/', include(test_client.get_urls())),
]
Server and Client object imported correctly. I think client is working good but I dont know Server works. Maybe Server doesn't work correctly. Need to solve this.
SSO_SERVER needs a slash at the end:
SSO_SERVER='http://127.0.0.1:8000/server/'
Root cause is the coexistance of server and client in one app.
when you request /client/ there will be a request to get a token:
(see https://github.com/divio/django-simple-sso/blob/master/simple_sso/sso_client/client.py )
class LoginView(View):
...
def get(self, request):
...
request_token = self.client.get_request_token(redirect_to)
...
which will built an url from
SSO_SERVER='http://127.0.0.1:8000/server/' + reverse('simple-sso-request-token')
because you have the server in your server urls, reverse('simple-sso-request-token') returns "/server/request-token/"
Together you get
http://127.0.0.1:8000/server/server/request-token/
I am not sure if the path name "simple-sso-request-token" is needed somewhere else - if not, you could just "overwrite" it by adding a line with a dummy view to the urls.py just to make the reverse result change:
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
re_path(r'^server/', include(test_server.get_urls())),
re_path(r'^client/', include(test_client.get_urls())),
path("request-token/", some_dummy_view , name='simple-sso-request-token'), # this is only to force reverse("simple-sso-request-token") to return "request-token/"
]
(reverse() returns the last path in the urlpatterns list)
This will lead to
http://127.0.0.1:8000/server/request-token/
hope there is no further error messages
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.