Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tool I source to get some query functions for CIS Person API
export person_api_client_id=xxx
export person_api_client_secret=xxx
export audience=api.sso.mozilla.com
export api_domain=person.api.sso.mozilla.com
if [ -z "$person_api_bearer_token" ]; then
echo "Fetching bearer token"
export person_api_bearer_token=$(curl \
--silent \
--request POST \
--url https://auth.mozilla.auth0.com/oauth/token \
--header "Content-Type: application/json" \
--data "{\"client_id\":\"${person_api_client_id}\",\"client_secret\":\"${person_api_client_secret}\",\"audience\":\"${audience}\",\"grant_type\":\"client_credentials\"}" | jq -r '.access_token')
fi
function url_quote {
echo $1 | python3 -c "import urllib.parse; print(urllib.parse.quote(input()))"
}
function get_user_from_userid {
curl --silent -H "Authorization: Bearer ${person_api_bearer_token}" "https://${api_domain}/v2/user/user_id/$(url_quote "$1")" | python3 -m json.tool
}
function get_user_from_email {
curl --silent -H "Authorization: Bearer ${person_api_bearer_token}" "https://${api_domain}/v2/user/primary_email/$(url_quote "$1")" | python3 -m json.tool
}
function get_user_from_username {
curl --silent -H "Authorization: Bearer ${person_api_bearer_token}" "https://${api_domain}/v2/user/primary_username/$(url_quote "$1")" | python3 -m json.tool
}
function strip_sigs {
jq 'walk(if type == "object" then with_entries(select(.key | test("signature|metadata") | not)) else . end) | walk(if type == "object" and has("values") then .values else . end) | walk(if type == "object" and has("value") then .value else . end)'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment