Skip to content

Instantly share code, notes, and snippets.

@xgp
xgp / get-keycloak-active-sessions.py
Created July 25, 2024 17:10 — forked from nickbabkin/get-keycloak-active-sessions.py
Get total number of active Keycloak sessions per client
'''
USAGE:
1) Create client in Keycloak and enable client authentication + service account roles for it
2) Assign "view-realm" role from realm-management client on "service account roles" tab for the client
3) Replace keycloak_url and realm_name variables with your Keycloak base dir
4) Export client credentials into $CLIENTID and CLIENTSECRET env variable
5) python get-keycloak-active-sessions.py
'''
import requests
@xgp
xgp / keycloak-mssql-docker-compose.yml
Created April 12, 2023 19:50
running keycloak with mssql using docker-compose
version: '3'
volumes:
mssql_data:
driver: local
caddy_data:
driver: local
services:
mssql:
@xgp
xgp / openapi.yaml
Last active October 31, 2024 06:03
OpenAPI specification for Keycloak account API
openapi: 3.0.2
info:
title: Keycloak Account API
version: 20.0.3
description: |
Derived from the code at https://github.com/keycloak/keycloak/blob/main/services/src/main/java/org/keycloak/services/resources/account/AccountRestService.java
components:
securitySchemes:
access_token:
type: http
@xgp
xgp / org-create.sh
Created October 6, 2022 15:26
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")
@xgp
xgp / Dockerfile
Last active August 12, 2024 17:56
Keycloak 17 example using JGroups JDBC_PING discovery protocol for Infinispan
FROM quay.io/keycloak/keycloak:17.0.0 as builder
ENV KC_METRICS_ENABLED=true
ENV KC_FEATURES=preview
ENV KC_DB=postgres
ENV KC_HTTP_RELATIVE_PATH=/auth
# specify the custom cache config file here
ENV KC_CACHE_CONFIG_FILE=cache-ispn-jdbc-ping.xml
# copy the custom cache config file into the keycloak conf dir
@xgp
xgp / ExampleTest.java
Created October 28, 2021 08:55
JUnit4 Keycloak Rule
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.keycloak.admin.client.Keycloak;
import org.keycloak.representations.idm.RealmRepresentation;
public class ExampleTest {
@xgp
xgp / gist:a853e80351e832070511a8ec7d0fda78
Last active December 7, 2016 10:57
Using swagger codegen Java with APIs that require 2- or 3-legged OAuth1
import se.akerfeldt.okhttp.signpost.OkHttpOAuthConsumer;
import se.akerfeldt.okhttp.signpost.SigningInterceptor;
....
// Using the default Java
DefaultApi api = new DefaultApi();
ApiClient client = api.getApiClient();
// Put the interceptor in the http client
OkHttpClient http = client.getHttpClient();
#!/bin/bash
echo '=================================================='
echo '===============Install necessary tools==============='
echo '=================================================='
sudo yum update
sudo yum install git make flex bison libtool automake openssl-devel libevent libevent-devel python-devel gcc-c++ byacc java-1.7.0-openjdk ant
echo '=================================================='