Initial commit: git-hangman-lab and keycloak-hangman-lab skills
This commit is contained in:
51
keycloak-hangman-lab/scripts/keycloak/set-name
Executable file
51
keycloak-hangman-lab/scripts/keycloak/set-name
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Get the directory where this script is located
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
|
||||
# Optional explicit username
|
||||
username=""
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--username)
|
||||
username="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
echo "Usage: $0 [--username <username>]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Default to pass_mgr if not provided
|
||||
if [[ -z "$username" ]]; then
|
||||
username=$(pass_mgr get-username --key keycloak)
|
||||
fi
|
||||
|
||||
if [[ -z "$username" ]]; then
|
||||
echo "Error: No keycloak username found in pass_mgr"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
realm="Hangman-Lab"
|
||||
|
||||
# Check if user exists
|
||||
result=$("$SCRIPT_DIR/kcadm" get users -r "$realm" -q "username=$username")
|
||||
user_count=$(echo "$result" | jq 'length')
|
||||
|
||||
if [[ "$user_count" -eq 0 ]]; then
|
||||
echo "Error: User $username not found in Keycloak"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get user ID
|
||||
userid=$(echo "$result" | jq -r '.[0].id')
|
||||
|
||||
# Set firstName and lastName
|
||||
"$SCRIPT_DIR/kcadm" update users/"$userid" -r "$realm" \
|
||||
--set "firstName=$username" \
|
||||
--set "lastName=$username"
|
||||
|
||||
echo "Name set for user: $username (firstName=$username, lastName=$username)"
|
||||
Reference in New Issue
Block a user