feat:密码加密

This commit is contained in:
dzc committed 2026-08-09 15:11:30 +08:00
1 parent 0398148db7
commit 223a199ae8
2 files changed
+37 -11

No files matched your search

+22 -11
View File
@@ -1,6 +1,7 @@
import base64 from "base64-utf8"
import request from "@/sheep/utils/request"
import { encryption } from "../utils/encryption"
// 将 Basic Auth 字符串提取为常量
const BASIC_AUTH = "Basic " + base64.encode(import.meta.env.VITE_OAUTH2_APP_CLIENT)
@@ -48,21 +49,31 @@ export default {
// 账号密码登录
login: (params: any) => {
const { username, password, randomStr, code, grant_type, scope } = params
const encKey = import.meta.env.VITE_PWD_ENC_KEY
// 未配置密钥时只能明文(需与 auth 客户端 encFlag 一致);或显式 VITE_OAUTH_PWD_PLAIN=true
const plainPwd = import.meta.env.VITE_OAUTH_PWD_PLAIN === "true" || !encKey
const pwdForWire = plainPwd ? password : encryption(password, encKey)
const query: Record<string, string> = {
username: username ?? "",
grant_type: grant_type ?? "",
scope: scope ?? "",
}
if (randomStr != null && String(randomStr) !== "") {
query.randomStr = String(randomStr)
}
if (code != null && String(code) !== "") {
query.code = String(code)
}
return request({
url: `/auth/oauth2/token`,
method: "POST",
params: {
username,
randomStr,
code,
grant_type,
scope,
},
data: { password },
params: query,
data: `password=${encodeURIComponent(pwdForWire)}`,
// data: `password=`+password,
header: {
skipToken: true,
Authorization: BASIC_AUTH,
"content-type": "application/x-www-form-urlencoded",
"Content-Type": "application/x-www-form-urlencoded",
},
})
},
@@ -112,7 +123,7 @@ export default {
}),
// 设备认证
verifyDevice: (data: { mobilePhone: string; code: string, deviceUniqueCode?: string }) =>
verifyDevice: (data: { mobilePhone: string; code: string; deviceUniqueCode?: string }) =>
request({
url: "/thirdparty/thirdPartyOAth2/mini-app/verify-device",
method: "POST",
@@ -120,7 +131,7 @@ export default {
}),
// 判断该设备是否被验证
isVerifyDevice: (data: { mobile: string; userId: string, uniqueCode?: string, deviceUniqueCode?: string }) =>
isVerifyDevice: (data: { mobile: string; userId: string; uniqueCode?: string; deviceUniqueCode?: string }) =>
request({
url: "/thirdparty/thirdPartyOAth2/is-verify-device",
method: "POST",
+15
View File
@@ -0,0 +1,15 @@
import * as CryptoJS from "crypto-js"
/**
*加密处理
*/
export function encryption(src: string, keyWord: string) {
const key = CryptoJS.enc.Utf8.parse(keyWord)
// 加密
var encrypted = CryptoJS.AES.encrypt(src, key, {
iv: key,
mode: CryptoJS.mode.CFB,
padding: CryptoJS.pad.NoPadding,
})
return encrypted.toString()
}