GithubHelp home page GithubHelp logo

poc-oauth-client's Introduction

Reference

Keycloak
https://www.baeldung.com/?s=keycloak
https://www.baeldung.com/spring-boot-keycloak
https://www.baeldung.com/keycloak-oauth2-openid-swagger

Markdown (.md)
https://markdownguide.org/basic-syntax
https://markdownguide.org/extended-syntax

Error "finished with non-zero exit value 1"

Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
https://noame123.medium.com/spring-boot-execute-error-finished-with-non-zero-exit-value-1-5e8317e6ad92

Keycloak

Setup

https://keycloak.org/server/containers

docker run --name keycloak-server -p 38180:8080 \
-e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=keycloak \
quay.io/keycloak/keycloak:21.1 \
start-dev

login: admin
password: keycloak

Create New Realm

Keycloak create realm after login as admin 01 Keycloak create realm 02 Keycloak create client 01 Keycloak create client 02 Keycloak create client 03 Keycloak create client 04 Keycloak setup client redirect-uri Keycloak copy client secret 01

PKCE Setup

Clients -> Advanced -> Advanced Settings -> Proof Key for Code Exchange Code Challenge Method
PKCE setup 01 PKCE setup 02

Export and Import

Reference

https://howtodoinjava.com/devops/keycloak-export-import-realm/ https://howtodoinjava.com/devops/keycloak-script-upload-is-disabled/

Preparation

Remove the authorizationSettings block in the *realm.json files Remove authorizationSettings in json

Export

docker ps -a docker exec -it [container-id] bash

###example
docker exec -it e5c79daf5235 bash

execute export commands

cd /opt/keycloak
###including both realm and users data
###./kc.sh export --dir /tmp/keycloak-all-data-[yyyyMMdd]-[hh:mm]
./kc.sh export --dir /tmp/keycloak-all-data-20230623-1020
exit

kc.sh export ...

docker cp [container-id]:/tmp/keycloak-all-data-[yyyyMMdd]-[hh:mm] /local-somewhere-eg-tmp/

docker cp e5c79daf5235:/tmp/keycloak-all-data-20230623-1145 ~/Documents/development/artifact/keycloak/data-20230623-1145

docker cp ...

Import

Need to create the realm and import users manually with exported files
Create a new realm with json file 01 Create a new realm with json file 02 Create a new realm with json file 03 Import users 01 Import users 02 Import users 03 Import users 04 Import users 05 Import users 06

Timeout

Token timeout

Select the target realm, goto Realm settings. Token timeout 01
Token timeout 01

Postman

Working Offline

Click setting and then select Scratch Pad
Scratch Pad

Keycloak openid-configuration

According to the version of keycloak after v 17.0 and newer.
The url of openid-configuration api has been changed, /auth is removed.
From: {{server}}/auth/realms/{{realm}}/.well-known/openid-configuration To: {{server}}/realms/{{realm}}/.well-known/openid-configuration https://www.baeldung.com/postman-keycloak-endpoints

api: {{idp-server}}/realms/{{client-realm}}/.well-known/openid-configuration
Check openid-configuration

Authorization Code (with PKCE)

Authorization -> Grant type
Change Grant type to use Authorization Code (with PKCE)
Authorization Code (with PKCE)

Environment Variables Setup for Keycloak

environment variables preparation

app-server: http://localhost:28080
client-id: react-backend-client-01
client-secret: ${client-secret}
client-realm: react-backend-realm
idp-server: http://localhost:38180
idp-redirect_uri: {{app-server}}/v1/public/authorized
idp-auth-url: {{idp-server}}/realms/{{client-realm}}/protocol/openid-connect/auth
idp-access-token-url: {{idp-server}}/realms/{{client-realm}}/protocol/openid-connect/token

Postman environment setup 01

Collection auth setup

token name: access_token
grant type: Authorization Code
callback url: {{idp-redirect_uri}}
auth url: {{idp-auth-url}}
access token url: {{idp-access-token-url}}
client id: {{client-id}}
client secret: {{client-secret}}

Postman collection auth 01

Gradle

bootRun Setup

Prepare the following environment variables for bootRun

client-id=[client-id];client-secret=[client-secret];client-realm=[client-realm];oauth2.client.keycloak=[keycloak-host];spring.profiles.active=[spring profile]

client-id=oauth-client-01
client-secret=XXX
client-realm=oauth-client-realm
oauth2.client.keycloak=http://localhost:38180
spring.profiles.active=dev

gradlew bootRun

./gradlew bootRun --debug --args='--client-id=oauth-client-01 --client-secret=XXX --client-realm=oauth-client-realm --oauth2.client.keycloak=http://localhost:38180 --spring.profiles.active=dev'

poc-oauth-client's People

Contributors

siukatech avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.