org root add responsibility
This commit is contained in:
parent
11c79abc31
commit
856315b7bc
8 changed files with 74 additions and 45 deletions
|
|
@ -4,8 +4,8 @@ const KC_URL = process.env.KC_URL;
|
|||
const KC_REALMS = process.env.KC_REALMS;
|
||||
const KC_CLIENT_ID = process.env.KC_SERVICE_ACCOUNT_CLIENT_ID;
|
||||
const KC_SECRET = process.env.KC_SERVICE_ACCOUNT_SECRET;
|
||||
const AUTH_ACCOUNT_SECRET = process.env.AUTH_ACCOUNT_SECRET
|
||||
const API_KEY = process.env.API_KEY
|
||||
const AUTH_ACCOUNT_SECRET = process.env.AUTH_ACCOUNT_SECRET;
|
||||
const API_KEY = process.env.API_KEY;
|
||||
|
||||
let token: string | null = null;
|
||||
let decoded: DecodedJwt | null = null;
|
||||
|
|
@ -742,7 +742,6 @@ export async function removeUserGroup(userId: string, groupId: string) {
|
|||
// Function to change user password
|
||||
export async function changeUserPassword(userId: string, newPassword: string) {
|
||||
try {
|
||||
console.log(await getToken());
|
||||
const res = await fetch(`${KC_URL}/admin/realms/${KC_REALMS}/users/${userId}/reset-password`, {
|
||||
// prettier-ignore
|
||||
headers: {
|
||||
|
|
@ -788,27 +787,33 @@ export async function resetPassword(username: string) {
|
|||
// const tokenData = await tokenResponse.json();
|
||||
// const adminToken = tokenData.access_token;
|
||||
|
||||
const users = await fetch(`${KC_URL}/admin/realms/${KC_REALMS}/users?email=${encodeURIComponent(username)}`, {
|
||||
headers: {
|
||||
"authorization": `Bearer ${await getToken()}`,
|
||||
const users = await fetch(
|
||||
`${KC_URL}/admin/realms/${KC_REALMS}/users?email=${encodeURIComponent(username)}`,
|
||||
{
|
||||
headers: {
|
||||
authorization: `Bearer ${await getToken()}`,
|
||||
// "authorization": `Bearer ${adminToken}`,
|
||||
"content-type": `application/json`,
|
||||
},
|
||||
});
|
||||
if(!users.ok) {
|
||||
},
|
||||
);
|
||||
if (!users.ok) {
|
||||
return false;
|
||||
}
|
||||
const usersData = await users.json();
|
||||
const userId = usersData[0].id;
|
||||
const resetResponse = await fetch(`${KC_URL}/admin/realms/${KC_REALMS}/users/${userId}/execute-actions-email`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${await getToken()}`,
|
||||
// "Authorization": `Bearer ${adminToken}`,
|
||||
"Content-Type": "application/json"
|
||||
const resetResponse = await fetch(
|
||||
`${KC_URL}/admin/realms/${KC_REALMS}/users/${userId}/execute-actions-email`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: {
|
||||
Authorization: `Bearer ${await getToken()}`,
|
||||
// "Authorization": `Bearer ${adminToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(["UPDATE_PASSWORD"]),
|
||||
},
|
||||
body: JSON.stringify(["UPDATE_PASSWORD"])
|
||||
});
|
||||
);
|
||||
if (!resetResponse.ok) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -817,4 +822,4 @@ export async function resetPassword(username: string) {
|
|||
console.error("Error triggering password reset:", error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue