114 lines
3.7 KiB
VB.net
114 lines
3.7 KiB
VB.net
Imports System.Net
|
|
|
|
Public Class cMSEAPI
|
|
|
|
Public API_STRING
|
|
Dim API As New DataTable
|
|
Dim rest As New Chilkat.Rest
|
|
Dim SQL As New SQL
|
|
Dim apiSettingsloaded As Boolean = False
|
|
|
|
|
|
Sub New(program As String)
|
|
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
|
|
API = SQL.loadDgvBySql("SELECT top(1) * FROM tblAPIEinstellungen WHERE api_program='" & program & "' and api_productive ='" & IIf(VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM, "0", "1") & "'", "ADMIN")
|
|
If API.Rows.Count = 0 Then
|
|
MsgBox("keine gültigen API-Einstellungen für " & program & " gefunden!")
|
|
Else
|
|
apiSettingsloaded = True
|
|
API_STRING = API.Rows(0).Item("api_url")
|
|
End If
|
|
|
|
End Sub
|
|
|
|
|
|
Public Function createJWT(ByRef failureText As String) As String
|
|
Try
|
|
|
|
If apiSettingsloaded = False Then Return False
|
|
|
|
Dim jwt As New Chilkat.Jwt
|
|
|
|
' Build the JOSE header
|
|
Dim jose As New Chilkat.JsonObject
|
|
' Use HS256. Pass the string "HS384" or "HS512" to use a different algorithm.
|
|
Dim success As Boolean = jose.AppendString("alg", "HS256")
|
|
success = jose.AppendString("typ", "JWT")
|
|
|
|
' Now build the JWT claims (also known as the payload)
|
|
Dim claims As New Chilkat.JsonObject
|
|
success = claims.AppendString("iss", API.Rows(0).Item("api_user"))
|
|
'success = claims.AppendString("sub", "")
|
|
'success = claims.AppendString("aud", "http://example.com")
|
|
|
|
' Set the timestamp of when the JWT was created to now.
|
|
Dim curDateTime As Integer = jwt.GenNumericDate(0)
|
|
'success = claims.AddIntAt(-1, "iat", curDateTime)
|
|
|
|
' Set the "not process before" timestamp to now.
|
|
'success = claims.AddIntAt(-1, "nbf", curDateTime)
|
|
|
|
' Set the timestamp defining an expiration time (end time) for the token
|
|
' to be now + 1 hour (3600 seconds)
|
|
success = claims.AddIntAt(-1, "exp", curDateTime + 3600)
|
|
|
|
' Produce the smallest possible JWT:
|
|
jwt.AutoCompact = True
|
|
|
|
Dim strJwt As String = jwt.CreateJwt(jose.Emit(), claims.Emit(), API.Rows(0).Item("api_passwort"))
|
|
|
|
Debug.WriteLine(strJwt)
|
|
Return strJwt
|
|
|
|
Catch ex As WebException
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
End Try
|
|
|
|
End Function
|
|
|
|
Public Function getTransactions(jwt As String) As String
|
|
Try
|
|
Dim returnText As String = ""
|
|
Dim failureText As String = ""
|
|
|
|
|
|
|
|
Dim success As Boolean
|
|
rest.ClearAllQueryParams()
|
|
|
|
rest.AddHeader("X_API_KEY", jwt)
|
|
|
|
rest.IdleTimeoutMs = 5000
|
|
|
|
Dim responseJson As String = rest.FullRequestNoBody("GET", "/v1/transactions/new")
|
|
If (rest.LastMethodSuccess <> True) Then
|
|
Debug.WriteLine(rest.LastErrorText)
|
|
rest.IdleTimeoutMs = 30000 'defualt
|
|
Return "Fehler"
|
|
End If
|
|
|
|
If (rest.ResponseStatusCode <> 200) Then
|
|
Debug.WriteLine(rest.ResponseHeader)
|
|
Return "Fehler"
|
|
End If
|
|
|
|
Debug.WriteLine(responseJson)
|
|
|
|
|
|
Dim json As New Chilkat.JsonObject
|
|
success = json.Load(responseJson)
|
|
If (success <> True) Then
|
|
Debug.WriteLine(json.LastErrorText)
|
|
End If
|
|
|
|
Debug.WriteLine(json)
|
|
|
|
|
|
|
|
Catch ex As WebException
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
End Try
|
|
|
|
End Function
|
|
|
|
End Class |