2015-11-02 15:02:50 -06:00
|
|
|
-- Token authentication
|
|
|
|
|
-- Copyright (C) 2015 Atlassian
|
|
|
|
|
|
2016-08-02 12:34:32 -05:00
|
|
|
local jwt = require "luajwtjitsi";
|
2015-11-02 15:02:50 -06:00
|
|
|
|
|
|
|
|
local _M = {};
|
|
|
|
|
|
2016-08-23 14:42:49 -05:00
|
|
|
local function _verify_token(token, appId, appSecret, disableRoomNameConstraints)
|
2015-11-02 15:02:50 -06:00
|
|
|
|
2015-12-22 19:51:43 +01:00
|
|
|
local claims, err = jwt.decode(token, appSecret, true);
|
2015-11-18 12:49:36 -06:00
|
|
|
if claims == nil then
|
|
|
|
|
return nil, err;
|
2015-11-02 15:02:50 -06:00
|
|
|
end
|
|
|
|
|
|
2016-07-18 13:27:14 -05:00
|
|
|
local alg = claims["alg"];
|
|
|
|
|
if alg ~= nil and (alg == "none" or alg == "") then
|
|
|
|
|
return nil, "'alg' claim must not be empty";
|
|
|
|
|
end
|
|
|
|
|
|
2015-11-18 12:49:36 -06:00
|
|
|
local issClaim = claims["iss"];
|
|
|
|
|
if issClaim == nil then
|
2016-04-20 16:37:36 -05:00
|
|
|
return nil, "'iss' claim is missing";
|
2015-11-02 15:02:50 -06:00
|
|
|
end
|
2015-11-18 12:49:36 -06:00
|
|
|
if issClaim ~= appId then
|
|
|
|
|
return nil, "Invalid application ID('iss' claim)";
|
2015-11-02 15:02:50 -06:00
|
|
|
end
|
|
|
|
|
|
2015-11-18 12:49:36 -06:00
|
|
|
local roomClaim = claims["room"];
|
2016-06-13 16:11:44 -05:00
|
|
|
if roomClaim == nil and disableRoomNameConstraints ~= true then
|
2016-04-20 16:37:36 -05:00
|
|
|
return nil, "'room' claim is missing";
|
2015-11-18 12:49:36 -06:00
|
|
|
end
|
2015-12-22 19:51:43 +01:00
|
|
|
|
2016-08-26 14:41:06 -05:00
|
|
|
return claims;
|
2015-11-02 15:02:50 -06:00
|
|
|
end
|
|
|
|
|
|
2016-08-23 14:42:49 -05:00
|
|
|
function _M.verify_token(token, appId, appSecret, disableRoomNameConstraints)
|
|
|
|
|
return _verify_token(token, appId, appSecret, disableRoomNameConstraints);
|
2015-11-02 15:02:50 -06:00
|
|
|
end
|
|
|
|
|
|
2016-06-13 16:11:44 -05:00
|
|
|
return _M;
|