forked from NREL/api-umbrella
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ging/token_validation
New feature for OAuth2 Token Validation using Fiware Wilma PEP-Proxy, v0.1 OAuth2 authentication with FIWARE Pep Proxy only, next version need to allow OAuth2 token validation with any authentication service provider
- Loading branch information
Showing
6 changed files
with
124 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
return function(table) | ||
local numItems = 0 | ||
local inverted = {} | ||
for key, value in pairs(table) do | ||
inverted[value] = key | ||
if type(value)=="string" then | ||
inverted[value] = key | ||
else | ||
for k,v in pairs(value) do | ||
numItems = numItems + 1 | ||
end | ||
if numItems > 1 then | ||
value = value["name"] | ||
end | ||
inverted[value] = key | ||
end | ||
end | ||
|
||
return inverted | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
local http = require "resty.http" | ||
local cjson = require "cjson" | ||
local _M = {} | ||
-- Function to connect with the Pep Proxy service for checking if the token is valid and retrieve | ||
-- the user properties. The function takes the PEP Proxy host and port as parameters | ||
-- and sends a request with the header X-Auth-Token with the value of the token provided | ||
-- by the user. If the token is valid, PEP proxy sends a response with the user information | ||
-- asociated to the token, otherwise, it sends a message indicating the result of the | ||
-- validation process with his status, 404 , 402, etc. | ||
function _M.first(host, port, token) | ||
local result | ||
local httpc = http.new() | ||
httpc:set_timeout(45000) | ||
httpc:connect(host,port) | ||
local res, err = httpc:request({headers = {["X-Auth-Token"] = token}}) | ||
if res and res.status == 200 then | ||
local body, body_err = res:read_body() | ||
if not body then | ||
return nil, body_err | ||
end | ||
result = cjson.decode(body) | ||
end | ||
|
||
return result, err | ||
end | ||
|
||
return _M |