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.

Revisions

  1. myselfneerav revised this gist Sep 6, 2020. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions auth.lua
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,6 @@ ffi.cdef([[
    ]]);

    local accessToken = ""
    local result = 0
    local typeString = ffi.typeof("GoString")

    @@ -19,7 +18,7 @@ if ngx.var.http_Authorization and string.len(ngx.var.http_Authorization) > 0 the
    result = authlib.Authenticate(accessTokenString)

    if tonumber(result)~=0 then
    -- we are ok here and proceed to route to upstream
    -- proceed to route to upstream
    else
    return ngx.exit(ngx.HTTP_UNAUTHORIZED)
    end
  2. myselfneerav revised this gist Sep 6, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion auth.lua
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    local ffi = require("ffi")
    local authlib = ffi.load("/gateway/auth/main/auth.so")
    local authlib = ffi.load("/gateway/auth/main/libauth.so")

    ffi.cdef([[
    typedef long long GoInt64;
  3. myselfneerav revised this gist Sep 6, 2020. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion auth.lua
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,6 @@ ffi.cdef([[
    local accessToken = ""
    local result = 0
    local typeString = ffi.typeof("GoString")
    local unauthorizedJson={}

    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))
  4. myselfneerav revised this gist Sep 6, 2020. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion auth.lua
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    local ffi = require("ffi")
    local cjson = require("cjson")
    local authlib = ffi.load("/gateway/auth/main/auth.so")

    ffi.cdef([[
  5. myselfneerav created this gist Sep 6, 2020.
    32 changes: 32 additions & 0 deletions auth.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    local ffi = require("ffi")
    local cjson = require("cjson")
    local authlib = ffi.load("/gateway/auth/main/auth.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 accessToken = ""
    local result = 0
    local typeString = ffi.typeof("GoString")
    local unauthorizedJson={}

    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
    -- we are ok here and proceed to route to upstream
    else
    return ngx.exit(ngx.HTTP_UNAUTHORIZED)
    end

    else
    return ngx.exit(ngx.HTTP_UNAUTHORIZED)
    end