OAUTH2 API
This is a simple OAuth2 API that allows you to authenticate users and get their access token.
Endpoints
GET /authorize
POST /token
Requirements
- Mysql database for storing clients
- Redis database (optional for storing code)
- User service api (optional for password grant type)
Deployment
Podman
using makefile to build and run the service
make build
make run
Kubernetes
- Create Database Schema
kubectl port-forward svc/mysql 13306:3306 -n mysql-server
# in another terminal
kubectl exec -it -n mysql-server "$(kubectl get pod -l app=mysql -n mysql-server -o jsonpath={.items..metadata.name})" -- mysql -u root -p
# enter password: root
mysql> create database oauth2;
mysql> use oauth2;
- Deploy the Service
# Create Namespace
kubectl create namespace account-system
# Create ConfigMap
kubectl apply -f - <<EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: oauth2-api-config
namespace: account-system
data:
JOSE_URL: http://jose-api.istio-auth.svc.cluster.local
RBAC_URL: http://rbac-api.account-system.svc.cluster.local
DB_USER: root
DB_PASS: root
DB_HOST: mysql.mysql-server.svc.cluster.local:3306
DB_NAME: oauth2
REDIS_ENABLED: "false"
REDIS_ADDRESS: redis.redis-server.svc.cluster.local:6379
REDIS_PASSWORD: root
EOF
# Create ServiceAccount
kubectl apply -f - <<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
name: oauth2-api-serviceaccount
namespace: account-system
EOF
# Create Service
kubectl apply -f - <<EOF
apiVersion: v1
kind: Service
metadata:
name: oauth2-api
namespace: account-system
spec:
selector:
app: oauth2-api
ports:
- protocol: TCP
port: 80
targetPort: 8080
EOF
# Create Deployment
kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: oauth2-api
namespace: account-system
spec:
replicas: 1
selector:
matchLabels:
app: oauth2-api
template:
metadata:
labels:
app: oauth2-api
spec:
containers:
- name: oauth2-api
image: ghcr.io/byebyebymyai/oauth2-api:main
imagePullPolicy: Always
ports:
- containerPort: 8080
envFrom:
- configMapRef:
name: oauth2-api-config
EOF
# restart deployment
kubectl rollout restart deployment oauth2-api -n account-system
- Test
kubectl port-forward svc/oauth2-api 8080:80 -n account-system
curl -i http://localhost:8080/health