Commit graph

19 commits

Author SHA1 Message Date
Matthew Wild
51fea18a87 mod_tokenauth: Track last access time (last time a token was used) 2023-03-24 12:59:47 +00:00
Kim Alvefur
98922d54b1 plugins: Prefix module imports with prosody namespace 2023-03-24 13:15:28 +01:00
Kim Alvefur
14f896bf2d mod_tokenauth: Fix traceback in get_token_session()
Errors in sha256 becasue `token_secret` is nil since it was not passed
to _get_validated_token_info().

Looks like a simple oversight in ebe3b2f96cad
2023-03-21 20:43:42 +01:00
Matthew Wild
fc80e83b42 mod_tokenauth: Switch to new token format (invalidates existing tokens!)
The new format has the following properties:

- 5 bytes longer than the previous format
- The token now has separate 'id' and 'secret' parts - the token itself is no
  longer stored in the DB, and the secret part is hashed
- The only variable length field (JID) has been moved to the end
- The 'secret-token:' prefix (RFC 8959) is now included

Compatibility with the old token format was not maintained, and all previously
issued tokens are invalid after this commit (they will be removed from the DB
if used).
2023-03-21 14:33:29 +00:00
Matthew Wild
5019bacff6 mod_tokenauth: Log error when token validation fails 2023-03-21 14:04:39 +00:00
Kim Alvefur
566a991f84 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.
2023-03-16 12:18:23 +01:00
Kim Alvefur
7b7cad2b66 mod_tokenauth: Fix misplaced closing parenthesis
`type(x ~= y)` is always a string, thus truthy
2023-03-02 22:34:29 +01:00
Matthew Wild
9e02d322d8 mod_tokenauth: Gracefully handle missing tokens 2023-03-01 18:43:54 +00:00
Matthew Wild
b435f6d52a mod_tokenauth: Add SASL handler backend that can accept and verify tokens
This is designed for use by other modules that want to accept tokens issued
by mod_tokenauth, without duplicating all the necessary logic.
2023-03-01 13:04:36 +00:00
Matthew Wild
f3d152eb1b mod_tokenauth: Add some sanity checking of the new optional parameters 2023-03-01 13:02:51 +00:00
Matthew Wild
a58a6d2317 mod_tokenauth: Add 'purpose' constraint
This allows tokens to be tied to specific purposes/protocols. For example, we
shouldn't (without specific consideration) allow an OAuth token to be dropped
into a slot expecting a FAST token.

While FAST doesn't currently use mod_tokenauth, it and others may do in the
future. It's better to be explicit about what kind of token code is issuing or
expecting.
2023-03-01 13:01:21 +00:00
Matthew Wild
32c38bc249 mod_tokenauth: Allow attaching an arbitrary data table to a token 2022-10-13 22:46:19 +01:00
Matthew Wild
12fc0febf1 mod_tokenauth: Remove expired tokens from storage 2022-10-06 16:00:39 +01:00
Matthew Wild
36afd999b1 mod_tokenauth: Invalidate tokens issued before most recent password change
This is a security improvement, to ensure that sessions authenticated using a
token (note: not currently possible in stock Prosody) are invalidated just
like password-authenticated sessions are.
2022-10-06 15:59:07 +01:00
Matthew Wild
f5768f63c9 mod_authz_internal, and more: New iteration of role API
These changes to the API (hopefully the last) introduce a cleaner separation
between the user's primary (default) role, and their secondary (optional)
roles.

To keep the code sane and reduce complexity, a data migration is needed for
people using stored roles in 0.12. This can be performed with

  prosodyctl mod_authz_internal migrate <host>
2022-08-17 16:38:53 +01:00
Matthew Wild
a0f2f9ee19 mod_tokenauth: New API that better fits how modules are using token auth
This also updates the module to the new role API, and improves support for
scope/role selection (currently treated as the same thing, which they almost
are).
2022-07-20 10:52:17 +01:00
Matthew Wild
40bb67c03b mod_tokenauth: Track creation time of tokens 2020-02-28 21:55:40 +00:00
Kim Alvefur
92c65ed9af mod_tokenauth: Handle tokens issued to bare hosts (eg components) 2020-02-28 14:13:04 +01:00
Matthew Wild
f6a365c970 mod_authtokens: Rename to mod_tokenauth for consistency with mod_saslauth 2020-02-26 22:46:15 +00:00
Renamed from plugins/mod_authtokens.lua (Browse further)