mirror of
https://gitea.phreedom.club/localhost_frssoft/FMN_bot.git
synced 2024-11-23 13:43:01 +00:00
localhost_frssoft
b8b7b6f70b
* Added README * Custom browser variable for auth_helper.sh * Fix requirements * Fix dataset converter
59 lines
1.5 KiB
Bash
Executable File
59 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
default_auth_browser()
|
|
{
|
|
$browser $@
|
|
}
|
|
|
|
mkdir -m 711 -p .app_sessions
|
|
|
|
|
|
echo 'Input instance (example.example)'
|
|
read instance
|
|
|
|
echo 'Input client/app name (Example: FMN_bot)'
|
|
read client_name
|
|
|
|
export 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=$client_name" \
|
|
--data-urlencode 'redirect_uris=urn:ietf:wg:oauth:2.0:oob' \
|
|
--data-urlencode 'scopes=read write follow' \
|
|
--output ".app_sessions/$instance" \
|
|
--create-file-mode 0600
|
|
fi
|
|
}
|
|
|
|
auth_api_get_code()
|
|
{
|
|
auth_api_create_client
|
|
client_id=$(jq -r '.client_id' ".app_sessions/$instance")
|
|
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=$(jq -r '.client_id' ".app_sessions/$instance")
|
|
client_secret=$(jq -r '.client_secret' ".app_sessions/$instance")
|
|
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" | jq -r '.access_token')
|
|
echo > "$basedir"/.auth
|
|
chmod 600 "$basedir"/.auth
|
|
echo "$token" > "$basedir"/.auth
|
|
}
|
|
|
|
auth_api_get_token
|
|
|