Skip to content

Instantly share code, notes, and snippets.

@xgp
Created October 6, 2022 15:26
Show Gist options
  • Save xgp/f58cf86eff6e1e131427670b2d281191 to your computer and use it in GitHub Desktop.
Save xgp/f58cf86eff6e1e131427670b2d281191 to your computer and use it in GitHub Desktop.
Example to create org
#!/bin/bash
read -p 'Host (format https://euc1.auth.ac ): ' host
read -p 'Realm: ' realm
printf "\nThis user must have create-organization, manage-organizations, and view-organizations realm-management roles in order to create and manage new Organizations.\n"read -p 'Username: ' user
read -p 'Username: ' user
read -sp 'Password: ' pass
DIRECT_GRANT_RESPONSE=$(curl -i --request POST $host/auth/realms/$realm/protocol/openid-connect/token --header "Accept: application/json" --header "Content-Type: application/x-www-form-urlencoded" --data "grant_type=password&username=$user&password=$pass&client_id=admin-cli")
ACCESS_TOKEN=$(echo $DIRECT_GRANT_RESPONSE | grep "access_token" | sed 's/.*\"access_token\":\"\([^\"]*\)\".*/\1/g');
# get orgs
curl $host/auth/realms/$realm/orgs --header "Accept: application/json" --header "Authorization: Bearer $ACCESS_TOKEN"
# create an org
curl --request POST $host/auth/realms/$realm/orgs --header "Content-Type: application/json" --header "Accept: application/json" --header "Authorization: Bearer $ACCESS_TOKEN" -d '{"name":"fubar","displayName":"Foo Bar","url":"https://fubar.com"}'
# get orgs, again
curl $host/auth/realms/$realm/orgs --header "Accept: application/json" --header "Authorization: Bearer $ACCESS_TOKEN"
@xgp
Copy link
Author

xgp commented Oct 6, 2022

Required user roles:
Screen Shot 2022-10-06 at 5 28 13 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment