mirror of
https://gitea.phreedom.club/localhost_frssoft/dybr2fedi.git
synced 2024-11-25 21:11:27 +00:00
56 lines
1.5 KiB
Bash
Executable file
56 lines
1.5 KiB
Bash
Executable file
#!/bin/sh
|
|
default_auth_browser()
|
|
{
|
|
links $@
|
|
}
|
|
|
|
mkdir -m 711 -p .app_sessions
|
|
|
|
|
|
echo 'Input instance (example.example)'
|
|
read instance
|
|
|
|
instance_point="https://$instance/api/v1"
|
|
|
|
auth_api_create_client()
|
|
{
|
|
if [ ! -e ".app_sessions/$instance" ]; then
|
|
curl -s --compressed --url "$instance_point/apps" \
|
|
--data-urlencode 'client_name=dybr2fedi bridge' \
|
|
--data-urlencode 'redirect_uris=urn:ietf:wg:oauth:2.0:oob' \
|
|
--data-urlencode 'scopes=read write follow' \
|
|
--data-urlencode 'website=https://gitea.phreedom.club/localhost_frssoft/dybr2fedi' \
|
|
--output ".app_sessions/$instance" \
|
|
--create-file-mode 0600
|
|
fi
|
|
}
|
|
|
|
auth_api_get_code()
|
|
{
|
|
auth_api_create_client
|
|
client_id=$(jj -i ".app_sessions/$instance" client_id)
|
|
default_auth_browser "https://$instance/oauth/authorize?client_id=$client_id&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=read+write+follow"
|
|
echo 'Input token-code:'
|
|
read pass
|
|
}
|
|
|
|
auth_api_get_token()
|
|
{
|
|
auth_api_get_code
|
|
clear
|
|
client_id=$(jj -i ".app_sessions/$instance" client_id)
|
|
client_secret=$(jj -i ".app_sessions/$instance" client_secret)
|
|
token=$(curl -s --compressed --url "https://$instance/oauth/token" \
|
|
--data-urlencode 'grant_type=authorization_code' \
|
|
--data-urlencode "client_id=$client_id" \
|
|
--data-urlencode "client_secret=$client_secret" \
|
|
--data-urlencode "redirect_uri=urn:ietf:wg:oauth:2.0:oob" \
|
|
--data-urlencode 'scope=read write follow' \
|
|
--data-urlencode "code=$pass" | jj access_token)
|
|
echo > "$basedir"/.auth
|
|
chmod 600 "$basedir"/.auth
|
|
echo "$token" > "$basedir"/.auth
|
|
}
|
|
|
|
auth_api_get_token
|