Software /
code /
prosody
Annotate
util/envload.lua @ 12997:0a56b84ec4ad
mod_tokenauth: Support for creating sub-tokens
Properties of sub-tokens:
- They share the same id as their parent token
- Sub-tokens may not have their own sub-tokens (but may have sibling tokens)
- They always have the same or shorter lifetime compared to their parent token
- Revoking a parent token revokes all sub-tokens
- Sub-tokens always have the same JID as the parent token
- They do not have their own 'accessed' property - accessing a sub-token
updates the parent token's accessed time
Although this is a generic API, it is designed to at least fill the needs of
OAuth2 refresh + access tokens (where the parent token is the refresh token
and the sub-tokens are access tokens).
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 26 Mar 2023 16:46:48 +0100 |
parent | 12576:d1aacc6a81ac |
rev | line source |
---|---|
5020
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
1 -- Prosody IM |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
2 -- Copyright (C) 2008-2011 Florian Zeitz |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
3 -- |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
4 -- This project is MIT/X11 licensed. Please see the |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
5 -- COPYING file in the source package for more information. |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
6 -- |
8416
bc9cb23b604a
util.envload: Ignore "undefined variable" warning for loadstring [luacheck with strict 5.2 or 5.3 checks]
Kim Alvefur <zash@zash.se>
parents:
7930
diff
changeset
|
7 -- luacheck: ignore 113/setfenv 113/loadstring |
5020
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
8 |
12576
d1aacc6a81ac
util.envload: Remove Lua 5.1 method
Kim Alvefur <zash@zash.se>
parents:
8416
diff
changeset
|
9 local load = load; |
7924
8487fe9fc335
util.envload: Open file here instead of letting loadfile do it so that all return values from io.open can be collected
Kim Alvefur <zash@zash.se>
parents:
7728
diff
changeset
|
10 local io_open = io.open; |
5020
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
11 |
12576
d1aacc6a81ac
util.envload: Remove Lua 5.1 method
Kim Alvefur <zash@zash.se>
parents:
8416
diff
changeset
|
12 local function envload(code, source, env) |
d1aacc6a81ac
util.envload: Remove Lua 5.1 method
Kim Alvefur <zash@zash.se>
parents:
8416
diff
changeset
|
13 return load(code, source, nil, env); |
d1aacc6a81ac
util.envload: Remove Lua 5.1 method
Kim Alvefur <zash@zash.se>
parents:
8416
diff
changeset
|
14 end |
5020
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
15 |
12576
d1aacc6a81ac
util.envload: Remove Lua 5.1 method
Kim Alvefur <zash@zash.se>
parents:
8416
diff
changeset
|
16 local function envloadfile(file, env) |
d1aacc6a81ac
util.envload: Remove Lua 5.1 method
Kim Alvefur <zash@zash.se>
parents:
8416
diff
changeset
|
17 local fh, err, errno = io_open(file); |
d1aacc6a81ac
util.envload: Remove Lua 5.1 method
Kim Alvefur <zash@zash.se>
parents:
8416
diff
changeset
|
18 if not fh then return fh, err, errno; end |
d1aacc6a81ac
util.envload: Remove Lua 5.1 method
Kim Alvefur <zash@zash.se>
parents:
8416
diff
changeset
|
19 local f, err = load(fh:lines(2048), "@" .. file, nil, env); |
d1aacc6a81ac
util.envload: Remove Lua 5.1 method
Kim Alvefur <zash@zash.se>
parents:
8416
diff
changeset
|
20 fh:close(); |
d1aacc6a81ac
util.envload: Remove Lua 5.1 method
Kim Alvefur <zash@zash.se>
parents:
8416
diff
changeset
|
21 return f, err; |
5020
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
22 end |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
23 |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
24 return { envload = envload, envloadfile = envloadfile }; |