Giter VIP home page Giter VIP logo

auth-api-demo's Introduction

auth-api-demo

auth-api-demo

System Requirements

To compile and run this quickstart you will need:

  • JDK 17
  • Apache Maven 3.8.6
  • Spring Boot 3.0.6
  • Keycloak 21+
  • Docker 20+

Starting and Configuring the Keycloak Server

docker run --name keycloak -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin --network=host quay.io/keycloak/keycloak:21.0.0 start-dev --http-port=8180

You should be able to access your Keycloak Server at http://localhost:8180.

Log in as the admin user to access the Keycloak Administration Console. Username should be admin and password admin.

Import the realm configuration file to create a new realm called quickstart. For more details, see the Keycloak documentation about how to create a new realm.

Build and Run the Quickstart

mvn spring-boot:run

Test Access

curl -X POST http://localhost:8180/realms/quickstart/protocol/openid-connect/token -H 'content-type: application/x-www-form-urlencoded' -d 'client_id=authz-servlet&client_secret=secret' -d 'username=jdoe&password=jdoe&grant_type=password'
curl -X POST http://localhost:8180/realms/quickstart/protocol/openid-connect/token -H 'content-type: application/x-www-form-urlencoded' -d 'client_id=authz-servlet&client_secret=secret' -d 'username=alice&password=alice&grant_type=password'

You should be able to obtain tokens for any of these users:

Username Password Roles
jdoe jdoe user_premium
alice alice user

Verify Access

-----curl --location --request GET 'http://localhost:8080/' \
--header Authorization: Bearer xxxxxxx
-----curl --location --request GET 'http://localhost:8080/protected/premium' \
--header Authorization: Bearer xxxxxxx

References

Docker container

docker network create mynetwork

docker run --name keycloak --network=mynetwork -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin -p 8180:8180 quay.io/keycloak/keycloak:21.0.0 start-dev --http-port=8180

docker build -t anacondong/auth-api-demo .

docker run --name auth-api-demo --network=mynetwork -p 8080:8080 -e KEYCLOAK_URL_AUTH=http://keycloak:8180/auth -e KEYCLOAK_URL=http://keycloak:8180 -e "keycloak.auth-server-url=http://keycloak:8180/auth" anacondong/auth-api-demo

K8s deployment

docker build -t auth-api-demo . docker login -u xxx -p xxx << do login to my dockerHub docker tag auth-api-demo anacondong/auth-api-demo docker push anacondong/auth-api-demo

Deploy to k8s

cd helmChart helm template release-authapidemo ./helmChart -f ./helmChart/values.yaml > ./helmChart/manifest.yaml

helm template release-authapidemo ./helmChart -f ./helmChart/values.yaml << Generate yaml at console helm install authapidemo ./helmChart --values ./helmChart/values.yaml <<< Install and run k8s helm delete authapidemo

Apply k8s

kubectl get services kubectl apply -f ./helmChart/manifest.yaml kubectl port-forward service/authapidemoservice 8080:8080

kubectl delete -f ./helmChart/manifest.yaml

auth-api-demo's People

Contributors

anacondong 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.