Hi Tyk community!
I have developed a Golang plugin that I use like this:
"custom_middleware": {
"pre": [],
"auth_check": {
"name": "CheckAuthentication",
"path": "./plugins/keycloak/keycloak.so"
},
...
}
I’m using tykio/tyk-gateway:v3.2.2 version and I compile the plugin with:
docker run --rm -v `pwd`:/plugin-source tykio/tyk-plugin-compiler:v3.2.2 keycloak.so
The plugin gets called, but I always get the error:
{
"error": "Session state is missing or unset! Please make sure that auth headers are properly applied"
}
The code of the plugin is right now a simple test to allow any request:
func CheckAuthentication(rw http.ResponseWriter, r *http.Request) {
logger.Error("CheckAuthentication")
logger.Error(ctx.GetSession(r))
logger.Error(ctx.GetAuthToken(r))
accessToken := r.Header.Get(headers.Authorization)
session := &user.SessionState{
KeyID: accessToken,
MetaData: map[string]interface{}{
"token": accessToken,
},
}
logger.Error("CheckAuthentication 1")
ctx.SetSession(r, session, true)
logger.Error("CheckAuthentication 2")
logger.Error(ctx.GetAuthToken(r))
Logs are:
time="Dec 16 16:26:04" level=error msg=CheckAuthentication
time="Dec 16 16:26:04" level=error msg="<nil>"
time="Dec 16 16:26:04" level=error
time="Dec 16 16:26:04" level=error msg="CheckAuthentication 1"
time="Dec 16 16:26:04" level=error msg="CheckAuthentication 2"
time="Dec 16 16:26:04" level=error msg="Bearer eyJhbGciOiJSUzI1NiI.......BLABLABLA"
I had a similar plugin perfectly working on Tyk v2.9.2, but as is remarked in https://community.tyk.io/t/per-session-rate-limiting-in-ce-edition-not-working/4975/15 , now the signature of SetSession has changed.
Of course, the example in Golang plugins does not compile.
Any help would be appreciated. Thanks!