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'
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @rest int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
-- URL: https://demoauth.fatturazioneelettronica.aruba.it/auth/signin
DECLARE @bTls int
SELECT @bTls = 1
DECLARE @port int
SELECT @port = 443
DECLARE @bAutoReconnect int
SELECT @bAutoReconnect = 1
EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'demoauth.fatturazioneelettronica.aruba.it', @port, @bTls, @bAutoReconnect
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @rest, 'ConnectFailReason', @iTmp0 OUT
PRINT 'ConnectFailReason: ' + @iTmp0
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
RETURN
END
EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'grant_type', 'password'
EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'username', 'Utente'
EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'password', 'Password'
DECLARE @strResponseBody nvarchar(4000)
EXEC sp_OAMethod @rest, 'FullRequestFormUrlEncoded', @strResponseBody OUT, 'POST', '/auth/signin'
EXEC sp_OAGetProperty @rest, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 <> 1
BEGIN
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
RETURN
END
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @respStatusCode OUT
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Status Code = ' + @respStatusCode
PRINT 'Response Header:'
EXEC sp_OAGetProperty @rest, 'ResponseHeader', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Response Body:'
PRINT @strResponseBody
EXEC @hr = sp_OADestroy @rest
RETURN
END
DECLARE @jsonResponse int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jsonResponse OUT
EXEC sp_OAMethod @jsonResponse, 'Load', @success OUT, @strResponseBody
-- See the Online Tool for Generating JSON Parse Code
DECLARE @access_token nvarchar(4000)
DECLARE @token_type nvarchar(4000)
DECLARE @expires_in int
DECLARE @refresh_token nvarchar(4000)
DECLARE @client_id nvarchar(4000)
DECLARE @userName nvarchar(4000)
DECLARE @Issued nvarchar(4000)
DECLARE @Expires nvarchar(4000)
EXEC sp_OAMethod @jsonResponse, 'StringOf', @access_token OUT, 'access_token'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @token_type OUT, 'token_type'
EXEC sp_OAMethod @jsonResponse, 'IntOf', @expires_in OUT, 'expires_in'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @refresh_token OUT, 'refresh_token'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @client_id OUT, 'client_id'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @userName OUT, 'userName'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @Issued OUT, '".issued"'
EXEC sp_OAMethod @jsonResponse, 'StringOf', @Expires OUT, '".expires"'
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @jsonResponse
END
GO
{
"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"
}