Skip to content

Commit

Permalink
Code refactoring, adding injection of sub field as consumer id
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Kulik committed Sep 19, 2017
1 parent 4e82988 commit a67801f
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions kong/plugins/oidc/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,43 @@ function CustomHandler:access(config)

session.configure(config)

if tryIntrospect(oidcConfig) then
doAuthentication(oidcConfig)

ngx.log(ngx.DEBUG, "In plugin CustomHandler:proceeding with two legged authentication, requested path: " .. ngx.var.request_uri)
else
ngx.log(ngx.DEBUG, "In plugin CustomHandler:access NOT calling authenticate, requested path: " .. ngx.var.request_uri)
end

ngx.log(ngx.DEBUG, "In plugin CustomHandler:access Done")
end

else
function doAuthentication(oidcConfig)

local res, err = require("resty.openidc").authenticate(oidcConfig)
res = tryIntrospect(oidcConfig)
if res then

if err then
if config.recovery_page_path then
ngx.log(ngx.DEBUG, "Entering recovery page: " .. config.recovery_page_path)
return ngx.redirect(config.recovery_page_path)
end
utils.exit(500, err, ngx.HTTP_INTERNAL_SERVER_ERROR)
end
ngx.log(ngx.DEBUG, "In plugin CustomHandler:Valid access token detected, passing connection, requested path: " .. ngx.var.request_uri)

utils.injectUser({sub = res.sub})

if res and res.user then
utils.injectUser(res.user)
ngx.req.set_header("X-Userinfo", require("cjson").encode(res.user))
else

local res, err = require("resty.openidc").authenticate(oidcConfig)

if err then
if config.recovery_page_path then
ngx.log(ngx.DEBUG, "Entering recovery page: " .. config.recovery_page_path)
return ngx.redirect(config.recovery_page_path)
end
utils.exit(500, err, ngx.HTTP_INTERNAL_SERVER_ERROR)
end

if res and res.user then
utils.injectUser(res.user)
ngx.req.set_header("X-Userinfo", require("cjson").encode(res.user))
end

else
ngx.log(ngx.DEBUG, "In plugin CustomHandler:access NOT calling authenticate, requested path: " .. ngx.var.request_uri)
end

ngx.log(ngx.DEBUG, "In plugin CustomHandler:access Done")
end

function tryIntrospect(oidcConfig)
Expand Down

0 comments on commit a67801f

Please sign in to comment.