Mercurial > prosody-modules
annotate mod_rest/example/rest.sh @ 5858:761142ee0ff2
mod_http_oauth2: Reflect changes to defaults etc
- Resource owner password grant was disabled by default
- Tokens now include a hash of client_id making it possible to be
reasonable sure that they were issued to a particular client
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 05 Mar 2024 00:32:00 +0100 |
parents | e5ad3f1f48bd |
children | a9c75430cb26 |
rev | line source |
---|---|
5281
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 #!/bin/bash -eu |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 # Copyright (c) Kim Alvefur |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 # This file is MIT/X11 licensed. |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 |
5329
107d60c70c1a
mod_rest/rest.sh: List dependencies in comment
Kim Alvefur <zash@zash.se>
parents:
5281
diff
changeset
|
6 # Dependencies: |
107d60c70c1a
mod_rest/rest.sh: List dependencies in comment
Kim Alvefur <zash@zash.se>
parents:
5281
diff
changeset
|
7 # - https://httpie.io/ |
5636
b3484a112300
mod_rest/rest.sh: Update to use httpie-oauth2 plugin
Kim Alvefur <zash@zash.se>
parents:
5432
diff
changeset
|
8 # - https://hg.sr.ht/~zash/httpie-oauth2 |
5329
107d60c70c1a
mod_rest/rest.sh: List dependencies in comment
Kim Alvefur <zash@zash.se>
parents:
5281
diff
changeset
|
9 |
5637
acd2f397ce6b
mod_rest/rest.sh: Silence shellcheck SC1091
Kim Alvefur <zash@zash.se>
parents:
5636
diff
changeset
|
10 # shellcheck disable=SC1091 |
acd2f397ce6b
mod_rest/rest.sh: Silence shellcheck SC1091
Kim Alvefur <zash@zash.se>
parents:
5636
diff
changeset
|
11 |
5281
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 # Settings |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 HOST="" |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 DOMAIN="" |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 |
5666
e5ad3f1f48bd
mod_rest/rest.sh: Restore default read-only behavior and the -rw flag
Kim Alvefur <zash@zash.se>
parents:
5637
diff
changeset
|
16 SESSION="session-read-only" |
e5ad3f1f48bd
mod_rest/rest.sh: Restore default read-only behavior and the -rw flag
Kim Alvefur <zash@zash.se>
parents:
5637
diff
changeset
|
17 |
5281
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/restrc" ]; then |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 # Config file can contain the above settings |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 source "${XDG_CONFIG_HOME:-$HOME/.config}/restrc" |
5636
b3484a112300
mod_rest/rest.sh: Update to use httpie-oauth2 plugin
Kim Alvefur <zash@zash.se>
parents:
5432
diff
changeset
|
21 |
b3484a112300
mod_rest/rest.sh: Update to use httpie-oauth2 plugin
Kim Alvefur <zash@zash.se>
parents:
5432
diff
changeset
|
22 if [ -z "${SCOPE:-}" ]; then |
b3484a112300
mod_rest/rest.sh: Update to use httpie-oauth2 plugin
Kim Alvefur <zash@zash.se>
parents:
5432
diff
changeset
|
23 SCOPE="openid xmpp" |
b3484a112300
mod_rest/rest.sh: Update to use httpie-oauth2 plugin
Kim Alvefur <zash@zash.se>
parents:
5432
diff
changeset
|
24 fi |
5281
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 fi |
5432
1c52efb6fd42
mod_rest/rest.sh: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
5431
diff
changeset
|
26 |
5281
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 if [[ $# == 0 ]]; then |
5666
e5ad3f1f48bd
mod_rest/rest.sh: Restore default read-only behavior and the -rw flag
Kim Alvefur <zash@zash.se>
parents:
5637
diff
changeset
|
28 echo "${0##*/} [-h HOST] [-rw] [/path] kind=(message|presence|iq) ...." |
5281
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 # Last arguments are handed to HTTPie, so refer to its docs for further details |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 exit 0 |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 fi |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 if [[ "$1" == "-h" ]]; then |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 HOST="$2" |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 shift 2 |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 elif [ -z "${HOST:-}" ]; then |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 HOST="$(hostname)" |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 fi |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 |
5666
e5ad3f1f48bd
mod_rest/rest.sh: Restore default read-only behavior and the -rw flag
Kim Alvefur <zash@zash.se>
parents:
5637
diff
changeset
|
40 if [[ "$1" == "-rw" ]]; then |
e5ad3f1f48bd
mod_rest/rest.sh: Restore default read-only behavior and the -rw flag
Kim Alvefur <zash@zash.se>
parents:
5637
diff
changeset
|
41 # To e.g. save Accept headers to the session |
e5ad3f1f48bd
mod_rest/rest.sh: Restore default read-only behavior and the -rw flag
Kim Alvefur <zash@zash.se>
parents:
5637
diff
changeset
|
42 SESSION="session" |
e5ad3f1f48bd
mod_rest/rest.sh: Restore default read-only behavior and the -rw flag
Kim Alvefur <zash@zash.se>
parents:
5637
diff
changeset
|
43 shift 1 |
e5ad3f1f48bd
mod_rest/rest.sh: Restore default read-only behavior and the -rw flag
Kim Alvefur <zash@zash.se>
parents:
5637
diff
changeset
|
44 fi |
e5ad3f1f48bd
mod_rest/rest.sh: Restore default read-only behavior and the -rw flag
Kim Alvefur <zash@zash.se>
parents:
5637
diff
changeset
|
45 |
5281
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 if [[ "$HOST" != *.* ]]; then |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 # Assumes subdomain of your DOMAIN |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 if [ -z "${DOMAIN:-}" ]; then |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 DOMAIN="$(hostname -d)" |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 fi |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 if [[ "$HOST" == *:* ]]; then |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 HOST="${HOST%:*}.$DOMAIN:${HOST#*:}" |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 else |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 HOST="$HOST.$DOMAIN" |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 fi |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 fi |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 # For e.g /disco/example.com and such GET queries |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
60 GET_PATH="" |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 if [[ "$1" == /* ]]; then |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
62 GET_PATH="$1" |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
63 shift 1 |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 fi |
4ed65a6c2a6a
mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
65 |
5666
e5ad3f1f48bd
mod_rest/rest.sh: Restore default read-only behavior and the -rw flag
Kim Alvefur <zash@zash.se>
parents:
5637
diff
changeset
|
66 https --check-status -p b --"$SESSION" rest -A oauth2 -a "$HOST" --oauth2-scope "$SCOPE" "$HOST/rest$GET_PATH" "$@" |