Git Product home page Git Product logo

userservice's Introduction

UserService

Run Locally

  • Run local instance of Keycloak on port 8080
    docker run -p 8080:8080 --env KEYCLOAK_ADMIN=admin --env KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak start-dev
  • Option 1: Build and run the userservice executable, which is exposed on port 8000.
    make build
    ./out/bin/userservice
  • Option 2: Run userservice with the go run command, which is exposed on port 8000.
    go run .
  • Get token from the userservice
curl --location 'http://localhost:8000/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=admin' \
--data-urlencode 'password=admin' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_id=admin-cli'
  • A successful response means that the local Keycloak server and the userservice are working as expected.

Using FindUser API

Setup local Keycloak server instance with following test data

  • Get master realm token from Keycloak server
curl --location 'http://localhost:8080/realms/master/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=admin' \
--data-urlencode 'password=admin' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_id=admin-cli'
  • Create Engineers group
curl --location 'http://localhost:8080/admin/realms/master/groups' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
    "name": "fr1-eng"
}'
  • Create Managers group
curl --location 'http://localhost:8080/admin/realms/master/groups' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
    "name": "fr1-mgr"
}'
  • Create an Engineer User
curl --location 'http://localhost:8080/admin/realms/master/users' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data-raw '{
    "username": "eng1-test",
    "groups" : ["fr1-eng"],
    "enabled" : "true",
    "email" : "[email protected]",
    "firstName": "fn",
    "lastName": "ln",
    "attributes": { "org_id" : "rh", "is_internal" : "true", "org_admin": "true", "type" : "engineer"},
    "credentials" : [
        { "credentialData" : "fr1-eng", "temporary" : "false", "type" : "password", "value" : "fr1-eng" }
    ]
}'
  • Create a Manager User
curl --location 'http://localhost:8080/admin/realms/master/users' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data-raw '{
    "username": "mgr1-test",
    "groups" : ["fr1-mgr"],
    "enabled" : "true",
    "email" : "[email protected]",
    "firstName": "fn",
    "lastName": "ln",
    "attributes": { "org_id" : "rh", "is_internal" : "true", "org_admin": "true", "type" : "manager"},
    "credentials" : [
        { "credentialData" : "fr1-mgr", "temporary" : "false", "type" : "password", "value" : "fr1-mgr" }
    ]
}'

Use Find Users API in userservice

  • Call Find Users API with following criteria
# Search users with usernames
curl --location 'http://localhost:8000/users?org_id=rh&usernames=mgr1-test%2Ceng1-test'
# Search users with emails
curl --location 'http://localhost:8000/users?org_id=rh&emails=1%401.com%2C2%402.com'
# Search users with userids, remember to replace user ids below as they will be different in your case.
curl --location 'http://localhost:8000/users?org_id=rh&user_ids=c2979a54-b50e-473a-8ff8-0710f701e64f%2C3c577a73-d15a-4130-968b-1fdab10e0ee0'

Docker Tasks using Makefile

  • Build userservice Docker image
make docker-build
  • Push userservice Docker image
make docker-push

Using different environment variables with .env files

  • Currently the .env file is used for running the userservice locally on the host machine.
  • .env.docker file is used for running the userservice in docker on the host machine with Keycloak service.
  • Setting KEYCLOAK_ACCESS_TOKEN_PUBLIC_KEY property: This should be the public key used to get generate the JWT token. You can get this from keycloak at this path - Login to keycloak with admin privileges --> Go to the realm --> Realm settings --> keys tab --> By default JWT generations uses RS256, but you need to pick correct algorithm --> click on public key -- Copy and update the .env file. You can find default signature algorithm under realm settings --> tokens tab --> General section --> Default Signature Algorithm

userservice's People

Contributors

lokeshrangineni avatar rhkp 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.