Skip to content

Instantly share code, notes, and snippets.

View JRWu's full-sized avatar
🏢
In-Office Full Time

Jia Rong Wu JRWu

🏢
In-Office Full Time
View GitHub Profile
deny[x] {
request_permission[_] == "apis"
request_intent = "write"
listen_path := input.request.body.api_definition.proxy.listen_path
result := regex.match("^(\/|[a-z0-9-.]+|{[a-zA-Z0-9_]+})+$", listen_path)
rules:
paths-kebab-case:
description: Paths should be kebab-case.
message: "{{property}} should be kebab-case (lower-case and separated with hyphens)"
severity: warn
@JRWu
JRWu / UpstreamOAuth.go
Last active November 17, 2023 19:33
A custom Go plugin for Tyk illustrating a client_credentials exchange with an OAuth server to obtain a JWT.
package main
import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"github.com/TykTechnologies/tyk/config"
"io"
"net/http"
@JRWu
JRWu / sample_server.py
Created October 20, 2022 15:33
A gRPC Server implemented in Python used to handle middleware requests from Tyk.
import coprocess_object_pb2, coprocess_object_pb2_grpc
from coprocess_session_state_pb2 import SessionState
import grpc, time, json, gzip
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
from concurrent import futures
def MyPreMiddleware(coprocess_object):
@JRWu
JRWu / tyk_apidef_bodytransform_grpc.json
Created October 20, 2022 15:30
A Tyk API Definition reverse proxying to https://jsonplaceholder.typicode.com/ with a body transformation (running in a Python gRPC Server) applied on the response.
{
"api_id": "22c41d3bd44f4764543a704c8934ad0c",
"jwt_issued_at_validation_skew": 0,
"upstream_certificates": {},
"use_keyless": true,
"enable_coprocess_auth": false,
"base_identity_provided_by": "",
"custom_middleware": {
"pre": [],
"post": [],
@JRWu
JRWu / tyk_apidef_bodytransform.json
Last active October 18, 2022 17:30
A Tyk API Definition reverse proxying to https://jsonplaceholder.typicode.com/ with a body transformation (written in golang templating) applied on the response.
{
"api_id": "ad6fd896339b4c4c6763e4301e23c4ae",
"jwt_issued_at_validation_skew": 0,
"upstream_certificates": {},
"use_keyless": true,
"enable_coprocess_auth": false,
"base_identity_provided_by": "",
"custom_middleware": {
"pre": [],
"post": [],