Package: dsm-django-socialauth
Djagno DSM AuthenticationRequirementspython >= 3.6django >= 2.0social-auth-app-djangodjangorestframework-simplejwtInstallationpip install dsm-django-socialauthUsagePrerequisitemust bePROTOCOL://HOST/oauth/complete/dsmauth/note: Callback URL must be same with decarelation in urls.pyin this example usehttp://127.0.0.1/oauth/complete/dsmauth/in setting.pyINSTALLED_APPS=[...'social_django','dsmauth',...]add authentication backend in setting.pyAUTHENTICATION_BACKENDS=[...'django.contrib.auth.backends.ModelBackend','dsmauth.backend.dsmOAuth2',...]set client id and client secret in setting.pySOCIAL_AUTH_DSMAUTH_KEY='<client_id>'SOCIAL_AUTH_DSMAUTH_SECRET='<client_secret>'Sample SOCIAL_AUTH_PIPELINESOCIAL_AUTH_PIPELINE=['social_core.pipeline.social_auth.social_details','social_core.pipeline.social_auth.social_uid','social_core.pipeline.social_auth.social_user','social_core.pipeline.user.get_username','social_core.pipeline.user.create_user','social_core.pipeline.social_auth.associate_user','social_core.pipeline.social_auth.load_extra_data','social_core.pipeline.user.user_details','social_core.pipeline.social_auth.associate_by_email',]Add login redirectLOGIN_REDIRECT_URL='<path to redirect>'Setauth server name and urlOAUTH_DSM_SERVER_BASEURL='oauth.data.storemesh.com'BASE_BACKEND_URL='<backend domain> eg http://localhost:8000'(optional) If use in internal ip address for DSM VMsOAUTH_DSM_SCHEME="<http or https>"OAUTH_INTERNAL_IP="<internal oauth provider ip address>"See more detail aboutsocial-app-djangoin (https://github.com/python-social-auth/social-app-django)in urls.pyfromdjango.urlsimportpath,includefromdsmauth.completeimportcompleteurlpatterns=[...path('oauth/complete/<str:backend>/',complete,name='complete'),path('oauth/',include('social_django.urls',namespace='social')),path('authen/',include('dsmauth.urls'))...]in templatetemplate...<ahref="{% url 'social:begin' 'dsmauth' %}">Login with DSM</a><ahref="{% url 'logout' %}">LOGOUT</a>...signin with next...<ahref="{% url 'social:begin' 'dsmauth' %}?next={{ request.scheme }}://{{ request.get_host }}{% url 'admin:index' %}">Login with dsm</a>...If use backend-frontend (Client Site Render)can use authentication with JWTin settings.pyBASE_FRONTEND_URL='http://localhost:3000/'Authentication stepfrontend href to<BACKEND_URL>/oauth/login/dsmauthoptional<BACKEND_URL>/oauth/login/dsmauth/?callback=<FRONTEND_URI>FRONTEND_URI : domain frontend or localhost:xxxxdefault: use in backend settingsBASE_FRONTEND_URLandBASE_BACKEND_URLbackend authentication with oauth serverif authen complete backend callback to frontend<BASE_FRONTEND_URL>/callback?token=<REFRESH_TOKEN>note BASE_FRONTEND_URL in backend/settings.py previous stepfrontend request access token with refresh token viarequest[POST] : <BACKEND_URL>/authen/token/refresh/
body : {
    "refresh" : "<REFRESH_TOKEN IN STEP 3>"
}reponse{
    "access": "eyJ0eXAiOiJKV1Qi...ifZOpwg"
}frontend collect access(access token) for request apiHow to userequest to backendURL : <BACKEND>/api/xxx
HEADER : {
    'Authorization': "Bearer <ACCESS_TOKEN>"
}logout / sign outlogout href to<BACKEND_URL>/authen/logout/optional<BACKEND_URL>/authen/logout/?callback=<FRONTEND_URI>FRONTEND_URI : domain frontend or localhost:xxxxdefault: use in backend settingsBASE_FRONTEND_URLandBASE_BACKEND_URLOptional setup logadd settings insettings.pyMIDDLEWARE=[...'dsmauth.middleware.LogHeaderMiddleware',...]it's can get log in response headerX-Username : (string) username exmikeX-Error : (string) short traceback python exception exFile /backend/searchapp/views.py, line 6, in error
i = 10/0
ZeroDivisionError: division by zeroOptional use JWT middlewareMIDDLEWARE=[...'dsmauth.middleware.JWTauthenticationMiddleware',...]if pass jwt token in header can userequest.userSignIn Admin via Oauthediturls.py...admin.site.login_template='admin/custom-login.html'admin.site.index_template='admin/custom-index.html'admin.site.site_title="<PROJECT NAME>"admin.site.site_header="<PROJECT NAME>"...