Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds event for parsed jwt and check for required token.context #13973

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions resources/prosody-plugins/mod_auth_token.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ local host = module.host;

-- Extract 'token' param from URL when session is created
function init_session(event)
local session, request = event.session, event.request;
local query = request.url.query;
local session, request = event.session, event.request;
local query = request.url.query;

if query ~= nil then
if query ~= nil then
local params = formdecode(query);

-- The following fields are filled in the session, by extracting them
Expand All @@ -41,32 +41,32 @@ module:hook_global("bosh-session", init_session);
module:hook_global("websocket-session", init_session);

function provider.test_password(username, password)
return nil, "Password based auth not supported";
return nil, "Password based auth not supported";
end

function provider.get_password(username)
return nil;
return nil;
end

function provider.set_password(username, password)
return nil, "Set password not supported";
return nil, "Set password not supported";
end

function provider.user_exists(username)
return nil;
return nil;
end

function provider.create_user(username, password)
return nil;
return nil;
end

function provider.delete_user(username)
return nil;
return nil;
end

function provider.get_sasl_handler(session)

local function get_username_from_token(self, message)
local function get_username_from_token(self, message)

-- retrieve custom public key from server and save it on the session
local pre_event_result = prosody.events.fire_event("pre-jitsi-authentication-fetch-key", session);
Expand Down Expand Up @@ -116,28 +116,28 @@ function provider.get_sasl_handler(session)
end

return res;
end
end

return new_sasl(host, { anonymous = get_username_from_token });
return new_sasl(host, { anonymous = get_username_from_token });
end

module:provides("auth", provider);

local function anonymous(self, message)

local username = generate_uuid();
local username = generate_uuid();

-- This calls the handler created in 'provider.get_sasl_handler(session)'
local result, err, msg = self.profile.anonymous(self, username, self.realm);
-- This calls the handler created in 'provider.get_sasl_handler(session)'
local result, err, msg = self.profile.anonymous(self, username, self.realm);

if result == true then
if (self.username == nil) then
self.username = username;
end
return "success";
else
return "failure", err, msg;
end
end
if result == true then
if (self.username == nil) then
self.username = username;
end
return "success";
else
return "failure", err, msg;
end
end

sasl.registerMechanism("ANONYMOUS", {"anonymous"}, anonymous);
11 changes: 11 additions & 0 deletions resources/prosody-plugins/token/util.lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,17 @@ function Util:process_and_verify_token(session, acceptedIssuers)
session.jitsi_meet_context_user = {};
session.jitsi_meet_context_user.id = claims["user_id"];
end

-- fire event that token has been verified and pass the session and the decoded token
prosody.events.fire_event('jitsi-authentication-token-verified', {
session = session;
claims = claims;
});

if session.contextRequired and claims["context"] == nil then
return false, "not-allowed", 'jwt missing required context claim';
end

return true;
else
return false, "not-allowed", msg;
Expand Down