Last active
September 6, 2020 11:31
-
-
Save myselfneerav/1305ad4e8b5793d75d92a2a0dab835ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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