update
This commit is contained in:
@@ -7,18 +7,8 @@ export default defineEventHandler(async (event) => {
|
||||
const url = getRequestURL(event)
|
||||
const config = useRuntimeConfig()
|
||||
|
||||
console.log("body: " + JSON.stringify(body))
|
||||
|
||||
// const apiSSOConfirm = 'https://auth.rssa.top/realms/sandbox/protocol/openid-connect/userinfo'
|
||||
const apiSSOConfirm = config.public.SSO_CONFIRM_URL
|
||||
|
||||
const jwt = body.jwt
|
||||
// const nip = body.nip
|
||||
// const role = body.role
|
||||
// const roleid = body.roleid
|
||||
// const shift = body.shift
|
||||
// const loginStatus = body.status_login
|
||||
const token = 'Bearer ' + jwt
|
||||
const token = 'Bearer ' + body.data.token
|
||||
|
||||
const res_sso = await fetch(apiSSOConfirm,
|
||||
{
|
||||
@@ -31,40 +21,17 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
console.log(res_sso)
|
||||
if (res_sso.status === 200) {
|
||||
const parts = jwt.split('.')
|
||||
|
||||
if (parts.count != 3) {
|
||||
// return ['error' => 'Invalid JWT format'];
|
||||
}
|
||||
|
||||
const header = Buffer.from(strtr(parts[0], '-_', '+/'), 'base64').toString('utf8')
|
||||
const payload = Buffer.from(strtr(parts[1], '-_', '+/'), 'base64').toString('utf8')
|
||||
|
||||
// const textDecoder = new TextDecoder('utf-8');
|
||||
// // Decode the header and payload
|
||||
// const decodedBinaryHead = atob(parts[0]);
|
||||
// const decodedBinaryPayload = atob(parts[0]);
|
||||
// const header = textDecoder.decode(Uint8Array.from(decodedBinaryHead, char => char.charCodeAt(0)));
|
||||
// const payload = textDecoder.decode(Uint8Array.from(decodedBinaryPayload, char => char.charCodeAt(0)));
|
||||
|
||||
const result = {
|
||||
'header': header,
|
||||
'payload': payload
|
||||
};
|
||||
|
||||
const apiOrigin = config.public.API_ORIGIN
|
||||
|
||||
const cleanOrigin = apiOrigin.replace(/\/+$/, '')
|
||||
const cleanPath = url.pathname.replace(/^\/api\//, '').replace(/^\/+/, '')
|
||||
const externalUrl = `${cleanOrigin}/${cleanPath}${url.search}`
|
||||
console.log("external url: " + externalUrl)
|
||||
console.log("body: " + JSON.stringify(body))
|
||||
|
||||
const resp = await fetch(externalUrl,
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
name: JSON.parse(payload).name,
|
||||
name: body.data.user.username,
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -73,27 +40,6 @@ export default defineEventHandler(async (event) => {
|
||||
},
|
||||
})
|
||||
|
||||
console.log(resp)
|
||||
// if (resp.status === 200) {
|
||||
// const data = await resp.json()
|
||||
|
||||
// if (data?.data?.accessToken) {
|
||||
// setCookie(event, 'authentication', data.data.accessToken, {
|
||||
// path: '/',
|
||||
// httpOnly: true,
|
||||
// sameSite: 'strict',
|
||||
// maxAge: 60 * 60 * 24,
|
||||
// })
|
||||
|
||||
// delete data.data.accessToken
|
||||
// // return data
|
||||
|
||||
// const { login } = useUserStore()
|
||||
// await login(resp.text())
|
||||
// await navigateTo('/')
|
||||
// }
|
||||
// }
|
||||
|
||||
return new Response(await resp.text(), {
|
||||
status: resp.status,
|
||||
headers: {
|
||||
@@ -109,14 +55,3 @@ export default defineEventHandler(async (event) => {
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
function strtr(str: string, fromChars: string, toChars: string) {
|
||||
let result = str;
|
||||
for (let i = 0; i < fromChars.length; i++) {
|
||||
const fromChar = fromChars[i] || '_-';
|
||||
// const toChar = toChars[i];
|
||||
// Use a global regex to replace all occurrences of the character
|
||||
result = result.replace(new RegExp(fromChar.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), toChars);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user