Skip to content

Instantly share code, notes, and snippets.

@myselfneerav
Last active September 6, 2020 11:31
Show Gist options
  • Select an option

  • Save myselfneerav/1305ad4e8b5793d75d92a2a0dab835ce to your computer and use it in GitHub Desktop.

Select an option

Save myselfneerav/1305ad4e8b5793d75d92a2a0dab835ce to your computer and use it in GitHub Desktop.
local ffi = require("ffi")
local authlib = ffi.load("/gateway/auth/main/libauth.so")
ffi.cdef([[
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef struct { const char *p; GoInt n; } GoString;
extern GoInt Authenticate(GoString p0);
]]);
local result = 0
local typeString = ffi.typeof("GoString")
if ngx.var.http_Authorization and string.len(ngx.var.http_Authorization) > 0 then
local accessTokenString= typeString(ngx.var.http_Authorization, string.len(ngx.var.http_Authorization))
result = authlib.Authenticate(accessTokenString)
if tonumber(result)~=0 then
-- proceed to route to upstream
else
return ngx.exit(ngx.HTTP_UNAUTHORIZED)
end
else
return ngx.exit(ngx.HTTP_UNAUTHORIZED)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment