Il metodo serve a richiedere un token di autenticazione. Tale token รจ necessario per invocare i metodi dei vari server della Fatturazione Elettronica (Resource Server) che sono protetti dal sistema.
curl -X POST https://demoauth.fatturazioneelettronica.aruba.it/auth/signin \
-H 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' \
-d 'grant_type=password' \
-d 'username=Utente' \
-d 'password=Password'
Dim rest As New ChilkatRest
Dim success As Long
' URL: https://demoauth.fatturazioneelettronica.aruba.it/auth/signin
Dim bTls As Long
bTls = 1
Dim port As Long
port = 443
Dim bAutoReconnect As Long
bAutoReconnect = 1
success = rest.Connect("demoauth.fatturazioneelettronica.aruba.it",port,bTls,bAutoReconnect)
If (success <> 1) Then
Debug.Print "ConnectFailReason: " & rest.ConnectFailReason
Debug.Print rest.LastErrorText
Exit Sub
End If
success = rest.AddQueryParam("grant_type","password")
success = rest.AddQueryParam("username","Utente")
success = rest.AddQueryParam("password","Password")
Dim strResponseBody As String
strResponseBody = rest.FullRequestFormUrlEncoded("POST","/auth/signin")
If (rest.LastMethodSuccess <> 1) Then
Debug.Print rest.LastErrorText
Exit Sub
End If
Dim respStatusCode As Long
respStatusCode = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
Debug.Print "Response Status Code = " & respStatusCode
Debug.Print "Response Header:"
Debug.Print rest.ResponseHeader
Debug.Print "Response Body:"
Debug.Print strResponseBody
Exit Sub
End If
Dim jsonResponse As New ChilkatJsonObject
success = jsonResponse.Load(strResponseBody)
' See the Online Tool for Generating JSON Parse Code
Dim access_token As String
Dim token_type As String
Dim expires_in As Long
Dim refresh_token As String
Dim client_id As String
Dim userName As String
Dim Issued As String
Dim Expires As String
access_token = jsonResponse.StringOf("access_token")
token_type = jsonResponse.StringOf("token_type")
expires_in = jsonResponse.IntOf("expires_in")
refresh_token = jsonResponse.StringOf("refresh_token")
client_id = jsonResponse.StringOf("client_id")
userName = jsonResponse.StringOf("userName")
Issued = jsonResponse.StringOf(""".issued""")
Expires = jsonResponse.StringOf(""".expires""")
{
"access_token": "571a08cd6275e81e",
"token_type": "bearer",
"expires_in": 1800,
"refresh_token": "262ac1f88ad1e9e5",
"client_id": "123456",
"userName": "Utente",
".issued": "Mon, 21 Jan 2019 16:36:17 GMT",
".expires": "Mon, 21 Jan 2019 17:06:17 GMT"
}