2015-11-02 21:02:50 +00:00
|
|
|
-- Token authentication
|
|
|
|
-- Copyright (C) 2015 Atlassian
|
|
|
|
|
2015-11-18 18:49:36 +00:00
|
|
|
local jwt = require "luajwt";
|
2015-11-02 21:02:50 +00:00
|
|
|
|
|
|
|
local _M = {};
|
|
|
|
|
2015-11-18 18:49:36 +00:00
|
|
|
local function verify_password_impl(password, appId, appSecret, roomName)
|
2015-11-02 21:02:50 +00:00
|
|
|
|
2015-11-18 18:49:36 +00:00
|
|
|
local claims, err = jwt.decode(password, appSecret, true);
|
|
|
|
if claims == nil then
|
|
|
|
return nil, err;
|
2015-11-02 21:02:50 +00:00
|
|
|
end
|
|
|
|
|
2015-11-18 18:49:36 +00:00
|
|
|
local issClaim = claims["iss"];
|
|
|
|
if issClaim == nil then
|
|
|
|
return nil, "Issuer field is missing";
|
2015-11-02 21:02:50 +00:00
|
|
|
end
|
2015-11-18 18:49:36 +00:00
|
|
|
if issClaim ~= appId then
|
|
|
|
return nil, "Invalid application ID('iss' claim)";
|
2015-11-02 21:02:50 +00:00
|
|
|
end
|
|
|
|
|
2015-11-18 18:49:36 +00:00
|
|
|
local roomClaim = claims["room"];
|
|
|
|
if roomClaim == nil then
|
|
|
|
return nil, "Room field is missing";
|
|
|
|
end
|
|
|
|
if roomName ~= nil and roomName ~= roomClaim then
|
|
|
|
return nil, "Invalid room name('room' claim)";
|
2015-11-02 21:02:50 +00:00
|
|
|
end
|
2015-11-18 18:49:36 +00:00
|
|
|
|
|
|
|
return true;
|
2015-11-02 21:02:50 +00:00
|
|
|
end
|
|
|
|
|
2015-11-18 18:49:36 +00:00
|
|
|
function _M.verify_password(password, appId, appSecret, roomName)
|
|
|
|
return verify_password_impl(password, appId, appSecret, roomName);
|
2015-11-02 21:02:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return _M;
|