added token generator and getting token from token.json
This commit is contained in:
parent
610aa05a38
commit
888a9f716b
|
@ -1,6 +1,5 @@
|
|||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Flurl;
|
||||
|
@ -125,7 +124,7 @@ public static class Program
|
|||
Console.WriteLine($"ccd name {ccdName} is already in use\n");
|
||||
return InvalidRequest;
|
||||
}
|
||||
|
||||
|
||||
return ps.Contains(NameQueryParam) ? ParseManualRequest(ps, ccdName!)
|
||||
: ps.Contains(UniqueIdQueryParam) ? await LookupInstallationNameByUniqueId(ccdName!)
|
||||
: ps.Contains(MachineSerialQueryParam) ? await LookupInstallationNameByMachineSerial(ccdName!)
|
||||
|
@ -138,7 +137,7 @@ public static class Program
|
|||
|
||||
//var installationName = await LookupInstallationNameByUniqueId(ccdName);
|
||||
|
||||
using var vrm = VrmAccount.Token(AccToken.Id, AccToken.Token);
|
||||
using var vrm = VrmAccount.Token(AccToken.idUser, AccToken.token);
|
||||
var installations = await vrm.GetInstallations();
|
||||
|
||||
var installationName = installations
|
||||
|
@ -154,8 +153,8 @@ public static class Program
|
|||
private static async Task<(String ccdName, String humanReadableName)?> LookupInstallationNameByMachineSerial(String ccdName)
|
||||
{
|
||||
Console.WriteLine($"looking up {ccdName} on VRM");
|
||||
|
||||
using var vrm = VrmAccount.Token(AccToken.Id, AccToken.Token);
|
||||
|
||||
using var vrm = VrmAccount.Token(AccToken.idUser, AccToken.token);
|
||||
var installations = await vrm.GetInstallations();
|
||||
|
||||
foreach (var installation in installations)
|
||||
|
@ -273,6 +272,11 @@ public static class Program
|
|||
|
||||
internal interface AccToken
|
||||
{
|
||||
public String Token { get; init; }
|
||||
public UInt64 Id { get; init; }
|
||||
public String token { get; init; }
|
||||
public String bearer { get; init; }
|
||||
public UInt64 idUser { get; init; }
|
||||
public String verification_mode { get; init; }
|
||||
public String idAccessToken { get; init; }
|
||||
public Boolean verification_sent { get; init; }
|
||||
public Boolean success { get; init; }
|
||||
}
|
|
@ -2,18 +2,30 @@
|
|||
## USAGE: ./newToken.sh -u USERNAME -p PASSWORD
|
||||
|
||||
|
||||
while getopts u:p: flag
|
||||
while getopts u:p:n: flag
|
||||
do
|
||||
case "${flag}" in
|
||||
u) username=${OPTARG};;
|
||||
p) password=${OPTARG};;
|
||||
n) name=${OPTARG};;
|
||||
esac
|
||||
done
|
||||
|
||||
curl --request POST \
|
||||
response=$(curl --request POST \
|
||||
--url https://vrmapi.victronenergy.com/v2/auth/login \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data '{
|
||||
"username": '$username',
|
||||
"password": '$password',
|
||||
}' > token.json
|
||||
--data '{"username":"'$username'","password":"'$password'","sms_token":null,"remember_me":false,"language":""}')
|
||||
|
||||
echo -n '{"bearer' > token.json
|
||||
token=$(echo $response | jq ".token")
|
||||
#echo ${token:1:-1}
|
||||
uid=$(echo $response | jq ".idUser")
|
||||
echo -n ${response:7:-1} >> token.json
|
||||
|
||||
response2=$(curl --request POST \
|
||||
--url https://vrmapi.victronenergy.com/v2/users/$uid/accesstokens/create \
|
||||
--header 'Content-Type: application/json' \
|
||||
--header 'x-authorization: Bearer '${token:1:-1} \
|
||||
--data '{"name":"'$name'"}')
|
||||
echo -n , >> token.json
|
||||
echo -n ${response2:1} >> token.json
|
|
@ -0,0 +1 @@
|
|||
{"bearer":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjJmYzY5NTNiMjhjNTg3NWQyMzQwNzM3ZjlhNGIzM2RjIn0.eyJ1aWQiOiI1NTQ1MCIsInRva2VuX3R5cGUiOiJkZWZhdWx0IiwiaXNzIjoidnJtYXBpLnZpY3Ryb25lbmVyZ3kuY29tIiwiYXVkIjoiaHR0cHM6Ly92cm1hcGkudmljdHJvbmVuZXJneS5jb20vIiwiaWF0IjoxNjc5NTg2ODU0LCJleHAiOjE2Nzk2NzMyNTQsImp0aSI6IjJmYzY5NTNiMjhjNTg3NWQyMzQwNzM3ZjlhNGIzM2RjIn0.AsLJU7qDPBHO-_FjVo9a8RbyoxhYrDrwZX7V3z4Xq8EoUulv2VyTqy9OXLpez4JI2FVAfSO5a7Amj4XvK1AWtDr9MxP07IBfPyMu5LLGTzjPMAJ6fvZbvZ-eRsP1-aARCFekMGoeSvEEBDrZB9_0kps4h9idQwwGwAby2Tya0vNGu6QEw9WmHcbL8qjvJzxavg8bK6Lttv2-3l_11iZoqiYLdXbwBi32GYK_sdwp-fbGvPE1d6g6eVll94JfSqNLZl9baijtOksx_Qouu7YB8knCgFNrx535d4iJtCkMv9xWztWXbevpSQiy9S8pCgLSpmHNztlVDjacEYyduwUzyw","idUser":55450,"verification_mode":"password","verification_sent":false,"success":true,"token":"108a1407da84afea182b8102a202a2c6b73e9bd6ad919f521033b09837e6e564","idAccessToken":"385119"}
|
Loading…
Reference in New Issue