Skip to content

Commit

Permalink
Merge pull request #12 from mkulikk/master
Browse files Browse the repository at this point in the history
Introspection functionality. Fixes issues
#8
#3
#11
  • Loading branch information
phirvone authored Sep 25, 2017
2 parents ec70401 + a67801f commit 994b0c2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ It can be used as a reverse proxy terminating OAuth/OpenID Connect in front of a
the origin server/services can be protected with the relevant standards without implementing those on
the server itself.

Introspection functionality add capability for already authenticated users and/or applications that
already posses acces token to go through kong. The actual token verification is then done by Resource Server.

## Dependencies

**kong-oidc** depends on the following package:
Expand Down
4 changes: 2 additions & 2 deletions kong-oidc-1.0.2-0.rockspec → kong-oidc-1.0.3-0.rockspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package = "kong-oidc"
version = "1.0.2-0"
version = "1.0.3-0"
source = {
url = "git://github.com/nokia/kong-oidc",
tag = "v1.0.2",
tag = "v1.0.3",
dir = "kong-oidc"
}
description = {
Expand Down
40 changes: 37 additions & 3 deletions kong/plugins/oidc/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ function CustomHandler:access(config)

session.configure(config)

doAuthentication(oidcConfig)

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 doAuthentication(oidcConfig)

res = tryIntrospect(oidcConfig)
if res then

ngx.log(ngx.DEBUG, "In plugin CustomHandler:Valid access token detected, passing connection, requested path: " .. ngx.var.request_uri)

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

else

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

if err then
Expand All @@ -43,11 +63,25 @@ function CustomHandler:access(config)
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)

-- If introspection endpoint is not set, the functionallity is considered as disabled
if not oidcConfig.introspection_endpoint then
return nil
end

local res, err = require("resty.openidc").introspect(oidcConfig)
if err then
return nil
end

return res

end

-- This module needs to return the created table, so that Kong
Expand Down
1 change: 1 addition & 0 deletions kong/plugins/oidc/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ return {
client_id = { type = "string", required = true },
client_secret = { type = "string", required = true },
discovery = { type = "string", required = true, default = "https://.well-known/openid-configuration" },
introspection_endpoint = { type = "string", required = false },
redirect_uri_path = { type = "string" },
scope = { type = "string", required = true, default = "openid" },
response_type = { type = "string", required = true, default = "code" },
Expand Down
1 change: 1 addition & 0 deletions kong/plugins/oidc/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function M.get_options(config, ngx)
client_id = config.client_id,
client_secret = config.client_secret,
discovery = config.discovery,
introspection_endpoint = config.introspection_endpoint,
redirect_uri_path = M.get_redirect_uri_path(ngx),
scope = config.scope,
response_type = config.response_type,
Expand Down

0 comments on commit 994b0c2

Please sign in to comment.