- https://dns.he.net account(or similar)
- https://freedns.afraid.org account(or similar)
- Wild card SSL certificates (https://punchsalad.com) for any domain selected in (2)
- Remote PostgreSQL database (like RDS)
- Google OAuth credentials
With valid accounts in dns.he.net and freedns.afraid.org, you can generate a wildcard ssl certificate, and assign subdomains to each service getting setup.
- Log into freedns.afraid.org
- Click on registry
- Click on your preferred domain
- Using the drop down set TYPE to NS
- Enter your preferred subdomain name in the subdomain field
- Enter “ns1.he.net” in the destination field.
- Fill in the captcha and click save
- Log into dns.he.net
- Click on add a new domain
- Enter the FQDN you just reserved on freedns.afraid.org
- Click add domain
- If you get a zone validation failed error. Try again after a while - the DNS records may take a while to propagate. You can use whatsmydns.net to monitor propagation.
- Create the following subdomains - oidc, api, and app
- Click New A
- Enter a subdomain name, server IP address, and set TTL to 5 mins
- Click submit.
- Go to https://punchsalad.com/ssl-certificate-generator/
- Enter the domain name from dns.he.net starting with an asterisk *.subdomain.domain.tld
- Enter an email address
- Select DNS
- Accept the TOS
- Click create
- Download the certificates, and upload them to the server - place them in the /certs in /Kauth.
- Rename the certificates - ca-bundle to bundle.crt, and private-key to priv.key
- Create databases for Kong, Keycloak and Django
- Update the .dev.env file with the correct database credentials for keycloak, kong, and django
- Update the .dev.env and the nginx.conf file with the respective hostnames created in dns.he.net
- Export the following environment variables
- export DJ_DB_PASS=
- export DJ_DB_HOST=
- export ECS_REGISTRY_ALIAS=
- export ECS_REGION=
- export KONG_PG_HOST=
- export KONG_PG_USER=
- export KONG_PG_PASSWORD=
- Install Docker
- sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
- Install Make
- sudo apt install make
- Install AWSCLI
- sudo apt install awscli
- Nginx
- make build-nginx
- make run-nginx
- Django
- make build-django
- make run-django
- Keycloak
- make build-keycloak
- make run-keycloak
- Kong
- make build-kong
- make migrate-kong
- make run-kong
sudo docker container ls
This project integrates three services, which should be accessible via subdomains created at https://dns.he.net. This repo is configured using https://kauth.okzk.com.
- Keycloak OAuth - https://oidc.kauth.okzk.com
- Django DRF - https://app.kauth.okzk.com
- Kong API Gateway - https://api.kauth.okzk.com
1. Setup Keycloak http://oidc.kauth.okzk.com
- Login at https://oidc.kauth.okzk.com. Find the credentials in the .dev.env file.
- Go to Clients > Create Client
- Enter kauthapp in the client id field and save
- Go to Clients > kauthapp > Service Account Roles
- Click Assign Role
- Click Filter by Origin dropdown, select master-realm.
- Search for manage-users.
- Select manage-users, then click Assign.
- Go to Clients > kauthapp > Settings > Capability Config
- Turn on Client authentication, select Standard flow, Service accounts roles then Save.
- Go to Clients > kauthapp > Credentials > Client secret
- Copy the Client secret.
- Go to Clients > kauthapp > Advanced > Advanced Settings
- Set Access Token Lifespan to 1 days (24hrs).
2. Setup Django APP http://app.kauth.okzk.com
- Login at https://app.kauth.okzk.com/admin or whichever subdomain you designated in dns.he.net.
- Find the admin default credentials in create-admin.sh script.
- Go to Oauth clients click add.
- Set the following fields and save:
- user -> djadmin
- client id -> kauthapp
- client secret -> client secret for kauthapp client on Keycloak
- realm -> master
- Get a user account from https://app.kauth.okzk.com
- Copy the api key from the users profile page
- Send the apikey in the header to retrieve an accesstoken
- Using curl
curl -H "apikey:m0j5ygb94v2IrNFLjB0vHxul5C3IpnYI" https://api.kauth.okzk.com/oauth/tokens/
- Using httpie
http api.kauth.okzk.com/api/v1/oauth/tokens/ apikey:m0j5ygb94v2IrNFLjB0vHxul5C3IpnYI
- Using curl
- The API will send the access token in a response
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ4cHEyN3Jib1hqdE1XTUo0S1VHQmFWbElYbFhURjJLVkVvcktJQlpGOGI4In0.eyJleHAiOjE2NzI4OTc3OTcsImlhdCI6MTY3Mjg2MTc5NywianRpIjoiZGU5YWU2NjYtMWI1Zi00MDBlLWE1YzctYjdkNTE1YzI4Y2E4IiwiaXNzIjoiaHR0cHM6Ly9vaWRjLmthdXRoLm9remsuY29tL3JlYWxtcy9tYXN0ZXIiLCJhdWQiOlsib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": "profile email", "token_type": "Bearer"
}```
USERDATA
retrieve | status code 200
GET /api/v1/users/userdata
Authorization: Bearer access_token
http api.kauth.okzk.com/api/v1/users/userdata/
[{"content": "Compilers are important", "id": 1}]
create | status code 201
POST /api/v1/users/userdata
Authorization: Bearer access_token
echo -n '{"content": "Another compiler post"}' | http api.kauth.okzk.com/api/v1/users/userdata
delete | status code 204
DELETE /api/v1/users/userdata
Authorization: Bearer access_token
http DELETE api.kauth.okzk.com/api/v1/users/userdata/ id=1
USERDATAPOINTS
retrieve | status code 200
GET /api/v1/users/userdatapoints
Authorization: Bearer access_token
http GET api.kauth.okzk.com/api/v1/users/userdatapoints/
[{"content": "Datapoints for compilers", "id": 3}]
create | status code 201
POST /api/v1/users/userdatapoints
Authorization: Bearer access_token
echo -n '{"content": "Datapoints for compilers"}' | http POST api.kauth.okzk.com/api/v1/users/userdata/userdatapoints
delete | status code 204
DELETE /api/v1/users/userdatapoints
Authorization: Bearer access_token
http DELETE api.kauth.okzk.com/api/v1/users/userdatapoints/ id=3
- Add OAuth as an alternative login method.
- Use a realm besides master realm on Keycloak.