49 lines
1.6 KiB
VB.net
49 lines
1.6 KiB
VB.net
Imports Newtonsoft.Json
|
|
Imports Newtonsoft.Json.Linq
|
|
|
|
Public Class cModalTransBase
|
|
Public Shared baseUrl As String = "https://app.modaltrans.com"
|
|
Shared http As New Chilkat.Http()
|
|
|
|
|
|
Private Shared API_Mail = "mdlapi@verag.ag"
|
|
Private Shared API_PWD = "Verag2023"
|
|
|
|
|
|
Public Sub New()
|
|
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
|
|
|
|
http.SetRequestHeader("Content-Type", "application/json")
|
|
End Sub
|
|
|
|
' Methode zur Authentifizierung und Abruf des Tokens
|
|
Public Shared Function Authenticate(ByRef authToken As String) As Boolean
|
|
Dim http As New Chilkat.Http()
|
|
Dim req As New Chilkat.HttpRequest()
|
|
req.AddParam("email", API_Mail)
|
|
req.AddParam("password", API_PWD)
|
|
|
|
' Wichtig: Kein JSON, sondern x-www-form-urlencoded!
|
|
req.ContentType = "application/x-www-form-urlencoded"
|
|
|
|
|
|
Dim resp As Chilkat.HttpResponse = http.PostUrlEncoded(baseUrl & "/api/v1/login", req)
|
|
|
|
If resp IsNot Nothing Then
|
|
Try
|
|
Dim json = JsonConvert.DeserializeObject(Of JObject)(resp.BodyStr)
|
|
authToken = json.SelectToken("auth_token")?.ToString()
|
|
Console.WriteLine("Token: " & authToken)
|
|
If Not String.IsNullOrEmpty(authToken) Then
|
|
Return True
|
|
End If
|
|
Catch ex As Exception
|
|
Console.WriteLine("Fehler beim Parsen des Tokens: " & ex.Message)
|
|
End Try
|
|
Else
|
|
Console.WriteLine("Authentifizierungsfehler: " & http.LastErrorText)
|
|
End If
|
|
|
|
Return False
|
|
End Function
|
|
End Class |