diff --git a/.env.dev b/.env.dev index 67dc8a10..18f9f10f 100644 --- a/.env.dev +++ b/.env.dev @@ -18,7 +18,7 @@ CASDOOR_SCOPE=openid profile email # Casdoor Providers → wecom(Name=wecom,与 prod 共用同一 Provider 即可) CASDOOR_WECOM_PROVIDER_HINT=wecom -AUTH_JWT_ISSUER=http://192.168.100.230:8870 +AUTH_JWT_ISSUER=http://ai.well-trust.com:8870 AUTH_JWT_AUDIENCE= AUTH_JWT_JWKS_URL=http://192.168.100.230:8870/.well-known/jwks diff --git a/.env.prod b/.env.prod index 1403763d..80fb676e 100644 --- a/.env.prod +++ b/.env.prod @@ -19,7 +19,7 @@ CASDOOR_SCOPE=openid profile email # Casdoor Providers → wecom:Name 字段(截图即为 wecom);Organization=organization_HX,Sub type=Internal,Scope=snsapi_userinfo CASDOOR_WECOM_PROVIDER_HINT=wecom -AUTH_JWT_ISSUER=http://192.168.100.230:8870 +AUTH_JWT_ISSUER=http://ai.well-trust.com:8870 AUTH_JWT_AUDIENCE=758be5fcba2df784fdb4 AUTH_JWT_JWKS_URL=http://192.168.100.230:8870/.well-known/jwks diff --git a/.env.test b/.env.test index 41830b45..c80fc520 100644 --- a/.env.test +++ b/.env.test @@ -15,7 +15,7 @@ CASDOOR_SCOPE=openid profile email # Casdoor Providers → wecom(Name=wecom) CASDOOR_WECOM_PROVIDER_HINT=wecom -AUTH_JWT_ISSUER=http://192.168.100.230:8870 +AUTH_JWT_ISSUER=http://ai.well-trust.com:8870 AUTH_JWT_AUDIENCE= AUTH_JWT_JWKS_URL=http://192.168.100.230:8870/.well-known/jwks diff --git a/Jenkinsfile b/Jenkinsfile index 9a6bbe40..d4fb0daa 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -51,35 +51,6 @@ pipeline { } } - stage('Validate Docker Inputs') { - steps { - sh ''' - set -e - test -f docker-compose.yml - test -f backend/Dockerfile - test -f "docs/(表+字段).md" - - if grep -Eq '^docs/?$' .dockerignore 2>/dev/null && ! grep -Fxq '!docs/(表+字段).md' .dockerignore; then - echo "[Validate Docker Inputs] .dockerignore excludes docs, but docs/(表+字段).md is not re-included." - echo "[Validate Docker Inputs] Please keep docs/(表+字段).md in the Docker build context for Text2SQL." - exit 1 - fi - - if ! grep -Fq 'context: .' docker-compose.yml || ! grep -Fq 'dockerfile: backend/Dockerfile' docker-compose.yml; then - echo "[Validate Docker Inputs] docker-compose.yml must build hxops-backend from repository root with backend/Dockerfile." - exit 1 - fi - - if ! grep -Fq 'COPY docs/(表+字段).md /app/docs/(表+字段).md' backend/Dockerfile; then - echo "[Validate Docker Inputs] backend/Dockerfile must copy docs/(表+字段).md into the image." - exit 1 - fi - - echo "[Validate Docker Inputs] Docker build context and Text2SQL schema inputs are ready." - ''' - } - } - stage('Detect Changes') { steps { script { diff --git a/backend/.env b/backend/.env index 6257c36f..f33b2036 100644 --- a/backend/.env +++ b/backend/.env @@ -6,9 +6,11 @@ INTEGRATION_API_KEY=I76mSQZQEPYU6TubMhjh-xLsCgWC0gSIg5MncJFHFCvqvVlg-gZ_BvwO_UEL AUTH_JWT_REQUIRED=true AUTH_LOGIN_MODE=casdoor +# 如果需要用户密码登录,修改该值为password +# AUTH_LOGIN_MODE=password # Casdoor JWT 验签三件套 -AUTH_JWT_ISSUER=http://192.168.100.230:8870 +AUTH_JWT_ISSUER=http://ai.well-trust.com:8870 AUTH_JWT_AUDIENCE=758be5fcba2df784fdb4 AUTH_JWT_JWKS_URL=http://192.168.100.230:8870/.well-known/jwks diff --git a/backend/app/auth_jwt.py b/backend/app/auth_jwt.py index 63e06299..0fd9591d 100644 --- a/backend/app/auth_jwt.py +++ b/backend/app/auth_jwt.py @@ -136,6 +136,24 @@ def _decode_jwt(token: str) -> dict: ) +def _extract_unverified_claims(token: str) -> dict: + """Best-effort decode without signature verification for troubleshooting logs.""" + try: + return jwt.decode( + token, + options={ + 'verify_signature': False, + 'verify_exp': False, + 'verify_iat': False, + 'verify_nbf': False, + 'verify_aud': False, + 'verify_iss': False, + }, + ) or {} + except Exception: + return {} + + def _resolve_user_from_claims(claims: dict) -> Optional[User]: # Resolution order keeps compatibility with different token claim conventions. user_id = claims.get('user_id') or claims.get('id') @@ -195,6 +213,16 @@ def get_current_user() -> Optional[User]: ) except Exception: # Any decode/lookup failure should behave as unauthenticated. + unverified = _extract_unverified_claims(token) + expected_issuer = (current_app.config.get('AUTH_JWT_ISSUER') or '').strip() + expected_audience = (current_app.config.get('AUTH_JWT_AUDIENCE') or '').strip() + current_app.logger.error( + '[auth_jwt] decode context token_iss=%s token_aud=%s expected_iss=%s expected_aud=%s', + unverified.get('iss'), + unverified.get('aud'), + expected_issuer, + expected_audience, + ) current_app.logger.exception('[auth_jwt] decode failed token=%s path=%s', _token_brief(token), request.path) user = None claims = None diff --git a/deploy.sh b/deploy.sh index a431f377..765865da 100755 --- a/deploy.sh +++ b/deploy.sh @@ -5,6 +5,7 @@ set -e # Hxops 部署脚本 (优化版) # 用途: 自动拉取代码、构建前端、重启容器 # 使用: ./deploy.sh +# 备注:该文件用于手动在服务器上执行该脚本,Jenkins自动部署已不用该文件 # ============================================================================== echo "🚀 开始部署 Hxops..." diff --git a/frontend/src/config.ts b/frontend/src/config.ts index 21b7019a..3bc59950 100644 --- a/frontend/src/config.ts +++ b/frontend/src/config.ts @@ -4,7 +4,7 @@ export const config = { // Login mode switch: // - 'casdoor': submit username/password to backend Casdoor password-login API. // - 'password': submit to legacy local /api/user/login. - loginMode: 'password', + loginMode: 'casdoor', casdoor: { enabled: true, authorizeApi: '/api/user/casdoor/authorize-url',