aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-03-16 12:18:23 +0100
committerKim Alvefur <zash@zash.se>2023-03-16 12:18:23 +0100
commit566a991f8499d815314b695cb52959f334bcb9e9 (patch)
tree09b7f104dff8548c555e62e9199633917f789596 /util
parent944c25f3522f0ae649b2e9d04729bf2278387744 (diff)
downloadprosody-566a991f8499d815314b695cb52959f334bcb9e9.tar.gz
prosody-566a991f8499d815314b695cb52959f334bcb9e9.zip
util.sasl.oauthbearer: Return username from callback instead using authzid (BC)
RFC 6120 states that > If the initiating entity does not wish to act on behalf of another > entity, it MUST NOT provide an authorization identity. Thus it seems weird to require it here. We can instead expect an username from the token data passed back from the profile. This follows the practice of util.sasl.external where the profile callback returns the selected username, making the authentication module responsible for extracting the username from the token.
Diffstat (limited to 'util')
-rw-r--r--util/sasl/oauthbearer.lua36
1 files changed, 3 insertions, 33 deletions
diff --git a/util/sasl/oauthbearer.lua b/util/sasl/oauthbearer.lua
index 939c5385..490a205f 100644
--- a/util/sasl/oauthbearer.lua
+++ b/util/sasl/oauthbearer.lua
@@ -1,8 +1,4 @@
-local saslprep = require "util.encodings".stringprep.saslprep;
-local nodeprep = require "util.encodings".stringprep.nodeprep;
-local jid = require "util.jid";
local json = require "util.json";
-local log = require "util.logger".init("sasl");
local _ENV = nil;
@@ -32,37 +28,13 @@ local function oauthbearer(self, message)
return "failure", "malformed-request";
end
- local username = jid.prepped_split(gs2_authzid);
-
- if not username or username == "" then
- return "failure", "malformed-request", "Expected authorization identity in the username@hostname format";
- end
-
- -- SASLprep username
- username = saslprep(username);
-
- if not username or username == "" then
- log("debug", "Username violates SASLprep.");
- return "failure", "malformed-request", "Invalid username.";
- end
-
- local _nodeprep = self.profile.nodeprep;
- if _nodeprep ~= false then
- username = (_nodeprep or nodeprep)(username);
- if not username or username == "" then
- return "failure", "malformed-request", "Invalid username or password."
- end
- end
-
- self.username = username;
-
local token = auth_header:match("^Bearer (.+)$");
- local correct, state, token_info = self.profile.oauthbearer(self, username, token, self.realm);
+ local username, state, token_info = self.profile.oauthbearer(self, token, self.realm, gs2_authzid);
if state == false then
return "failure", "account-disabled";
- elseif state == nil or not correct then
+ elseif state == nil or not username then
-- For token-level errors, RFC 7628 demands use of a JSON-encoded
-- challenge response upon failure. We relay additional info from
-- the auth backend if available.
@@ -72,9 +44,7 @@ local function oauthbearer(self, message)
["openid-configuration"] = token_info and token_info.oidc_discovery_url or nil;
});
end
-
- self.resource = token_info.resource;
- self.role = token_info.role;
+ self.username = username;
self.token_info = token_info;
return "success";