我正在尝试使用 Angular、Django、IIS 服务器实现单点登录。
在 IIS Windows 身份验证中启用。
角度拦截器代码:
intercept(req: HttpRequest<any>, next: HttpHandler):Observable<HttpEvent<any>> {
console.log("in intercept")
req = req.clone({
withCredentials: true });
return next.handle(req); }
姜戈settings.py
:
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.RemoteUserMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',]
AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.RemoteUserBackend',)
CORS_ORIGIN_ALLOW_ALL = True
ALLOWED_HOSTS = ["*"]
获取错误:(IP 地址)已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。
在 settings.py 中试试这个配置
CORS_ORIGIN_ALLOW_ALL = 真 CORS_ALLOW_CREDENTIALS = 真
CORS_ALLOW_CREDENTIALS = True # 使用 withCredentials 时需要此项:true
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句