keycloak 4.8 Rest API - keycloak

I'm trying to retrive the users list of a specific realm.
I've read this documentation uri schema user resource
So i've tried the following curl cmd:
curl \
-X GET \
-H "Authorization: bearer $KC_ACCESS_TOKEN" \
"http://localhost:8080/auth/$KC_REALM/users"
I got a 404 error.
The user exist in the realm and has the view-users role.
This is the docker-compose file that i'm using to test then env (docker-compose.yml)

Try:
curl \
-X GET \
-H "Authorization: bearer $KC_ACCESS_TOKEN" \
"http://localhost:8080/auth/admin/$KC_REALM/users"

Try this
curl \
-X GET \
-H "Authorization: bearer $KC_ACCESS_TOKEN" \
"http://localhost:8080/auth/admin/realms/{realm}/users"

Related

Github REST Api get workflow runs for a specific date range with cURL

I am trying to query Github's REST API to list workflow runs for specific date ranges.
Here's an example curl call:
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/[OWNER]/[REPO]/actions/runs?created:2023-01-01..2023-01-02"
From what I understand from the documentation, this is how I should be able to retrieve only results from Jan 1st and 2nd of 2023. But it does not work, my result is always the latest runs.
What am I doing wrong?
you should use the = symbol instead of :, like:
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/[OWNER]/[REPO]/actions/runs?created=2023-01-01..2023-01-02"

Unable to access github API getting bad credentials error

I am trying to add a custom code check for a PR. After doing some research I found out that it can be done using the API mentioned below.
POST /repos/{owner}/{repo}/check-runs
Initially, it was giving me this error:
{
"message": "You must authenticate via a GitHub App.",
"documentation_url": "https://docs.github.com/rest/reference/checks#create-a-check-run"
}
I followed the guideline provided in this link.
I created a GitHub app.
Gave it required permission.
Generated a private key.
Generated a JWT token using the private key.
Installed the Github app in the repo too
I created a curl request:
curl --location --request POST 'https://api.github.com/repos/X/X-app/check-runs' \
--header 'Accept: application/vnd.github.v3+json' \
--header 'Authorization: Bearer eyJhbGciOiJSUzI1NiJ9.X.X-X-SAFvDnSkaJDjMI2T_BAC2iLlRZ7uNyFSe-X-UgFBFjoFrwsbcYFKfDM8f3FNPYpA6afhr18DLZ6rzu35klA' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "loremipsum"
}'
But, now I am getting this error
{
"message": "Bad credentials",
"documentation_url": "https://docs.github.com/rest"
}
I am not sure what I am missing here.
I figured this out. The GH documentation is a bit unclear/misleading. Here are the steps to make this work:
with the JWT bearer token, list your installations and note the installation id for your app
$ curl -i \
-H "Authorization: Bearer YOUR_JWT" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/app/installations
then get an installation access token for the above id
$ curl -i -X POST \
-H "Authorization: Bearer YOUR_JWT" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/app/installations/:installation_id/access_tokens
then with that token create the check run but use "Authorization: token" header
curl -i -H "Authorization: token YOUR_INSTALLATION_ACCESS_TOKEN"

Configuration of reCAPTCHA for Keycloak via CLI

Is there a way to configure reCAPTCHA via the CLI for a Keycloak standalone installation? To be more precise, is it possible to carry out all the steps described here in the Keycloak docs with the help of kcadm.sh?
You can achieve that by using Keycloak Admin REST API.
The first step is to get an admin token, so that one can call the Rest API:
curl -d "client_id=admin-cli" \
-d "username=$ADMIN_NAME" \
-d "password=$ADMIN_PASSWORD" \
-d "grant_type=password" \
https://$KEYCLOAK_IP/auth/realms/master/protocol/openid-connect/token
You will get a json response with the admin token. Extract the access token from that response (lets called $ACCESS_TOKEN).
Now, we need to get the list of all executions linked to the registration flow:
curl -X GET https://$KEYCLOAK_IP/auth/admin/realms/$REALM_NAME/authentication/flows/registration/executions \
-H "Content-Type: application/json" \
-H "Authorization: bearer $ACCESS_TOKEN"
From that json response, extract the id of the "providerId=registration-recaptcha-action". Lets call that id, $ID_RECAPTCHA.
Next make the reCaptcha required at the registration:
CAPTCHA_DATA='{"id":"$ID_RECAPTCHA","requirement":"REQUIRED","providerId":"registration-recaptcha-action"}'
curl -X PUT https://$KEYCLOAK_IP/auth/admin/realms/$REALM_NAME/authentication/flows/registration/executions \
-H "Content-Type: application/json" \
-H "Authorization: bearer $ACCESS_TOKEN"\
-d "$JSON_DATA"
Finally, to configure your own captcha:
CONFIG_DATA='{"config":{"site.key":"<YOUR SITE KEY>","secret":"<YOUR SECRET>","useRecaptchaNet":"<True or False>"},"alias":"<The CAPTCHA ALIAS>"}'
curl -X POST https://$KEYCLOAK_IP/auth/admin/realms/$REALM_NAME/authentication/executions/$ID_RECAPTCHA/config \
-H "Content-Type: application/json" \
-H "Authorization: bearer $ACCESS_TOKEN"\
Next, the best thing is to automatize this process with, for instance, some bash scripts.

How to add a label to an issue using GitHub API?

I'm trying to find a way to add a label to a GitHub issue using the API. After checking the API documentation I tried the following curl request:
curl -X POST -H "Authorization: token OOOOOOOOOOOOOOOO" -H \
"Accept: application/vnd.github.symmetra-preview+json" \
-d #label.json https://api.github.com/repos/CHSUNSONG/star-platform/issues/11
label.json contains:
["submitted"]
However, I got the following response:
{
"message": "Invalid request.\n\nFor 'links/1/schema', [\"submitted\"] is not an object.",
"documentation_url": "https://developer.github.com/v3/issues/#edit-an-issue"
}
Why isn't this working and how can I fix it?
You're POSTing to the wrong URL. Add /labels onto the end:
curl -X POST -H "Authorization: token OOOOOOOOOOOOOOOO" -H \
"Accept: application/vnd.github.symmetra-preview+json" \
-d #label.json \
https://api.github.com/repos/CHSUNSONG/star-platform/issues/11/labels

Request to VSTS REST API only works on Postman

I'm trying to run this request
curl -X POST \
'https://*****.visualstudio.com/DefaultCollection/_apis/wit/wiql?=&api-version=1.0' \
-H 'authorization: Basic *****' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: *****' \
-d '{
"query": "SELECT [System.Id] FROM WorkItems"
}'
but I keep getting this error
{"count":1,"value":{"Message":"A value is required but was not present in the request.\r\n"}}
It works as expected on Postman, so I think the request and the server are OK.
I'm trying to follow the first example shown here: https://www.visualstudio.com/en-us/docs/integrate/api/wit/wiql
Am I missing something?
The URL is wrong, remove =& from the REST API url and the url will be like this:
https://*****.visualstudio.com/DefaultCollection/_apis/wit/wiql?api-version=1.