-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4379 from esl/XEP-0484
XEP-0484 Fast Token Auth
- Loading branch information
Showing
34 changed files
with
1,740 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-module(time_helper). | ||
-export([validate_datetime/1]). | ||
|
||
%% @doc Validates that string is in ISO 8601 format | ||
-spec validate_datetime(string()) -> boolean(). | ||
validate_datetime(TimeStr) -> | ||
[Date, Time] = string:tokens(TimeStr, "T"), | ||
validate_date(Date) and validate_time(Time). | ||
|
||
validate_date(Date) -> | ||
[Y, M, D] = string:tokens(Date, "-"), | ||
Date1 = {list_to_integer(Y), list_to_integer(M), list_to_integer(D)}, | ||
calendar:valid_date(Date1). | ||
|
||
validate_time(Time) -> | ||
[T | _] = string:tokens(Time, "Z"), | ||
validate_time1(T). | ||
|
||
validate_time1(Time) -> | ||
[H, M, S] = string:tokens(Time, ":"), | ||
check_list([{H, 24}, {M, 60}, {S, 60}]). | ||
|
||
check_list(List) -> | ||
lists:all(fun({V, L}) -> I = list_to_integer(V), I >= 0 andalso I < L end, List). |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
## Module Description | ||
|
||
This module implements [XEP-0484: Fast Authentication Streamlining Tokens](https://xmpp.org/extensions/xep-0484.html). | ||
It provides services necessary to: | ||
|
||
* issue auth tokens for authenticated users; | ||
* reconnect to the server using the tokens instead of the original auth method. | ||
|
||
Tokens are stored in RDBMS. | ||
|
||
It is not related to another similar module `mod_auth_token`. | ||
|
||
## Options | ||
|
||
### `modules.mod_fast_auth_token.backend` | ||
* **Syntax:** non-empty string | ||
* **Default:** `"rdbms"` | ||
* **Example:** `backend = "rdbms"` | ||
|
||
Token storage backend. Currently only `"rdbms"` is supported. | ||
|
||
### `modules.mod_fast_auth_token.validity_period` | ||
* **Syntax:** TOML table. Each key is either `access` or `rotate_before_expire`.Each value is a nested TOML table with the following mandatory keys: `value` (non-negative integer) and `unit` (`"days"`, `"hours"`, `"minutes"` or `"seconds"`). | ||
* **Default:** `{access = {value = 3, unit = "days"}, rotate_before_expire = {value = 6, unit = "hours"}}` | ||
* **Example:** `validity_period.access = {value = 30, unit = "minutes"}` | ||
|
||
The user can use each token for `access` period of time before it expired. | ||
|
||
The server would [send](https://xmpp.org/extensions/xep-0484.html#token-rotation) | ||
a new token at the login time `rotate_before_expire` time before it expires. | ||
Set it to 0 to disable automatic rotation. | ||
|
||
## Example configuration | ||
|
||
```toml | ||
[modules.mod_fast_auth_token] | ||
validity_period.access = {value = 1, unit = "days"} | ||
validity_period.rotate_before_expire = {value = 0, unit = "days"} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.