AccessToken with Expiration Date previous to current
Problem reported by Bruno Gomes - 7/31/2020 at 10:25 AM
Submitted
Good afternoon, 

I am trying to implement a solution to reconstruct the users' folders using the API. I can authenticate and get AccessToken but when I try to run the RestoreFolders method I get the error: 401 Not Authorized. I noticed that the token's Expiration Date is exactly 45 minutes before the current time. I tried to do the RefreshToken but I get the same result. Is this the cause of the problem? What am I doing wrong? I need urgent help, please. Follow my code below:

Dim requestAuthentication As New RequestAuthentication()

        requestAuthentication.username = "admin"
        requestAuthentication.password = "admin123*"

        client.Headers.Add(HttpRequestHeader.ContentType, "application/json")

        Dim jsonStr As String = client.UploadString("http://localhost:9998/api/v1/auth/authenticate-user";, JsonConvert.SerializeObject(requestAuthentication))

        Dim responseAuthentication As ResponseAuthentication = JsonConvert.DeserializeObject(Of ResponseAuthentication)(jsonStr)
        accessToken = responseAuthentication.refreshToken

        Dim requestRefreshToken As New RequestRefreshToken()

        requestRefreshToken.token = responseAuthentication.refreshToken

        client.Headers.Add(HttpRequestHeader.ContentType, "application/json")
        jsonStr = client.UploadString("http://localhost:9998/api/v1/auth/refresh-token";, JsonConvert.SerializeObject(requestRefreshToken))

        Dim responseRefreshToken As ResponseRefreshToken = JsonConvert.DeserializeObject(Of ResponseRefreshToken)(jsonStr)
        accessToken = responseRefreshToken.accessToken

        client.Headers.Add("Authorization", accessToken)

        Dim requestRestoreFolders As New RequestRestoreFolders()

        requestRestoreFolders.restorations = New Restorations() With
            {
            .email = "bruno@zagloman.com",
            .folder = "Inbox",
            .recursive = False
            }

        jsonStr = client.UploadString("http://localhost:9998/api/v1/settings/sysadmin/restore-folders";, JsonConvert.SerializeObject(requestRestoreFolders))

        Dim responseRestoreFolders As ResponseRestoreFolders = JsonConvert.DeserializeObject(Of ResponseRestoreFolders)(jsonStr)
Thank's.

Reply to Thread