I'm trying to use the TTMSFNCCloudOAuth component with the Exact Online rest API.
This is working for the authentication, and getting the acces-token, refresh-token and Accesstoken expire datetime.
I'm loading the accesstoken, refreshtoken and the expiredatetime from a database.
When I check if the accesstoken is valid (TMSFNCCloudSample.Authentication.IsAccessTokenValid) it works fine.
But when the accesstoken datetime is expired nothings happening when I expected to get a new accesstaken when I call
procedure TfPoging2Form.Button2Click(Sender: TObject);
begin
TMSFNCCloudSample.FetchAccessToken.ThenBy(procedure (const AValue: string)
begin
If fPoging2Form.TMSFNCCloudSample.Authentication.IsAccessTokenValid Then begin
ShowMessage('Valid');
end
Else
Begin
ShowMessage('Not Valid');
end;
end);
end);
Looking at the code snippet, it's mostly OK. ShowMessage should be synced to the Main thread (see here), but that alone will not cause this to fail. Can you provide a minimal sample application so we can investigate?
Part of the problem for us is that I wanted to use port 8082, which resulted in the following error in debugger mode:
error:1407609C:SSL routines:SSL23_GET_CLIENT_HELLO:http request'.
Later, I read in the documentation (HTTPS Support - TMS FNC Cloud Pack) that the SSL certificate was automatically generated for port 443, but apparently not for other ports.
I've now set the port to 443, and now I'm getting more information back in the logging, especially because test tokens are now retrieving information.
The test tokens are being executed correctly, and I'm receiving the correct information from Exact.
What's still going wrong:
• Requesting a new access token when it has expired using FetchAccesstoken isn't working. Retrieving the token data from a database (which has expired) and then requesting a new access token doesn't work either.
The refresh token is valid in the database cases.
• TMSFNCCloudSample.OnConnected doesn't work. I don't receive a connected message.
TMSFNCCloudSample.OnConnected := CloudOAuthConnected;
TMSFNCCloudSample.Connect;
procedure TfProging2Form.CloudOAuthConnected(Sender: TObject);
begin
Memo1.Lines.Add('Connected. AccessToken: ' + TMSFNCCloudSample.Authentication.AccessToken);
end;
Looking at the documentation of Exact Online here, could it be you didn't implement the RetrieveRefreshToken override? It's the function that will be called when the refresh token is used to retrieve the new tokens.
If you haven't already, can you try something similar?