fastapi-react-postgres-keycloak-sso
https://github.com/fanqingsong/fastapi-react-postgres-keycloak-sso
version: "3" services: nginx: image: nginx:1.17 volumes: - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf - ./logs/nginx:/var/log/nginx ports: - 80:80 depends_on: - frontend - backend backend: restart: unless-stopped build: context: backend dockerfile: Dockerfile env_file: - .env environment: PYTHONPATH: . DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_USER} volumes: - ./logs/backend:/logs ports: - 8888:8888 depends_on: - postgres - keycloak frontend: build: context: frontend dockerfile: Dockerfile ports: - 8000:8000 environment: NODE_ENV: development CHOKIDAR_USEPOLLING: "true" keycloak: image: jboss/keycloak:12.0.4 environment: DB_VENDOR: POSTGRES DB_SCHEMA: public DB_ADDR: keycloak_postgres DB_DATABASE: ${KEYCLOAK_DB_DATABASE} DB_USER: ${KEYCLOAK_DB_USER} DB_PASSWORD: ${KEYCLOAK_DB_PASSWORD} KEYCLOAK_USER: ${KEYCLOAK_ADMIN_USERNAME} KEYCLOAK_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD} JDBC_PARAMS: "useSSL=false" ports: - 8080:8080 depends_on: - keycloak_postgres postgres: image: postgres restart: always environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} ports: - 5432:5432 volumes: - postgres_data:/var/lib/postgresql/data keycloak_postgres: image: postgres volumes: - keycloak_postgres_data:/var/lib/postgresql/data environment: POSTGRES_DB: ${KEYCLOAK_DB_DATABASE} POSTGRES_USER: ${KEYCLOAK_DB_USER} POSTGRES_PASSWORD: ${KEYCLOAK_DB_PASSWORD} volumes: postgres_data: keycloak_postgres_data:
python-keycloak
https://python-keycloak.readthedocs.io/en/latest/
from keycloak import KeycloakOpenID # Configure client keycloak_openid = KeycloakOpenID(server_url="http://localhost:8080/auth/", client_id="example_client", realm_name="example_realm", client_secret_key="secret") # Get WellKnown config_well_known = keycloak_openid.well_known() # Get Code With Oauth Authorization Request auth_url = keycloak_openid.auth_url( redirect_uri="your_call_back_url", scope="email", state="your_state_info") # Get Access Token With Code access_token = keycloak_openid.token( grant_type='authorization_code', code='the_code_you_get_from_auth_url_callback', redirect_uri="your_call_back_url") # Get Token token = keycloak_openid.token("user", "password") token = keycloak_openid.token("user", "password", totp="012345") # Get token using Token Exchange token = keycloak_openid.exchange_token(token['access_token'], "my_client", "other_client", "some_user") # Get Userinfo userinfo = keycloak_openid.userinfo(token['access_token']) # Refresh token token = keycloak_openid.refresh_token(token['refresh_token']) # Logout keycloak_openid.logout(token['refresh_token'])
标签:web,compose,postgres,grant,POSTGRES,DB,token,KEYCLOAK,keycloak From: https://www.cnblogs.com/lightsong/p/17400191.html