您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

util.lib.lua 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. -- Token authentication
  2. -- Copyright (C) 2015 Atlassian
  3. local jwt = require "luajwtjitsi";
  4. local _M = {};
  5. local function _get_room_name(token, appSecret)
  6. local claims, err = jwt.decode(token, appSecret);
  7. if claims ~= nil then
  8. return claims["room"];
  9. else
  10. return nil, err;
  11. end
  12. end
  13. local function _verify_token(token, appId, appSecret, roomName, disableRoomNameConstraints)
  14. local claims, err = jwt.decode(token, appSecret, true);
  15. if claims == nil then
  16. return nil, err;
  17. end
  18. local alg = claims["alg"];
  19. if alg ~= nil and (alg == "none" or alg == "") then
  20. return nil, "'alg' claim must not be empty";
  21. end
  22. local issClaim = claims["iss"];
  23. if issClaim == nil then
  24. return nil, "'iss' claim is missing";
  25. end
  26. if issClaim ~= appId then
  27. return nil, "Invalid application ID('iss' claim)";
  28. end
  29. local roomClaim = claims["room"];
  30. if roomClaim == nil and disableRoomNameConstraints ~= true then
  31. return nil, "'room' claim is missing";
  32. end
  33. if roomName ~= nil and roomName ~= roomClaim and disableRoomNameConstraints ~= true then
  34. return nil, "Invalid room name('room' claim)";
  35. end
  36. return true;
  37. end
  38. function _M.verify_token(token, appId, appSecret, roomName, disableRoomNameConstraints)
  39. return _verify_token(token, appId, appSecret, roomName, disableRoomNameConstraints);
  40. end
  41. function _M.get_room_name(token, appSecret)
  42. return _get_room_name(token, appSecret);
  43. end
  44. return _M;