ZRomik 2 Posted March 28, 2019 (edited) Hmmm I writed another small app only for rest auth. On form placed two components: TRestOAuth and TSslHttpRest. OAuth process is OK. I successfully got tokens. The OAuthRest process is bad. App still not executing procedure "onHttpRequestDone" inside component. Looks like I not set some parameters. Or Delphi do error while compiling app. Problem what inside component does't executing event handler OnRequestDone. And FResponseRaw field remains empty. When I comparing code in demo app and my own code I'm not seen big difference between them. I'm attach archive with my app. Can you look please and telling me where I'm do error? Debug.zip Edited March 28, 2019 by ZRomik Share this post Link to post
Angus Robertson 574 Posted March 28, 2019 3 hours ago, ZRomik said: Angus, this event raise one time inside component TSslHttpRest. I.e. procedure onHttpRequestDone calling only first time, when process authorization request. When I call procedure RestRequest this event does'nt raise. I can't understood why this strange thing happens. Perhaps you are confusing two different events. OnRequestDone is an event raised by the base component TSslHttpCli and is handled in TSslHttpRest to process the body stream response into ResponseRaw. The OnRestRequestDone event is then called by TSslHttpRest and that is where the REST response should be processed. If your application uses OnRequestDone instead of OnRestRequestDone, no content will be available. > autorefresh token not work if app in Idle, eg minimized to tray? Windows applications continue to run when minimised, but not if Windows goes to sleep or is suspended by power management. Angus Share this post Link to post
ZRomik 2 Posted March 28, 2019 (edited) 8 minutes ago, Angus Robertson said: Perhaps you are confusing two different events. OnRequestDone is an event raised by the base component TSslHttpCli and is handled in TSslHttpRest to process the body stream response into ResponseRaw. The OnRestRequestDone event is then called by TSslHttpRest and that is where the REST response should be processed. If your application uses OnRequestDone instead of OnRestRequestDone, no content will be available. > autorefresh token not work if app in Idle, eg minimized to tray? Windows applications continue to run when minimised, but not if Windows goes to sleep or is suspended by power management. Angus I'm understand. I speak about method inside component TSslHttpRest. That method does't executing when I manual execute procedure RestRequest(...). I'm process OnRestRequestDone event in my app but ResponseRaw property equal to empty string. Edited March 28, 2019 by ZRomik Share this post Link to post
Angus Robertson 574 Posted March 28, 2019 1 hour ago, ZRomik said: I'm understand. I speak about method inside component TSslHttpRest. That method does't executing when I manual execute procedure RestRequest(...). I'm process OnRestRequestDone event in my app but ResponseRaw property equal to empty string. If your application has OnRequestDone assigned, then that will override TSslHttpRest.onHttpRequestDone so it is never called, that is a design flaw of mine which I will fix next week. Angus Share this post Link to post
ZRomik 2 Posted March 28, 2019 17 minutes ago, Angus Robertson said: If your application has OnRequestDone assigned, then that will override TSslHttpRest.onHttpRequestDone so it is never called, that is a design flaw of mine which I will fix next week. Angus Good. Let's wait for the fix. But how it's work in demo app? Share this post Link to post
Angus Robertson 574 Posted March 28, 2019 47 minutes ago, ZRomik said: Good. Let's wait for the fix. But how it's work in demo app? I just told you, your application probably has the OnRequestDone event assigned, remove that and it will work properly. Angus Share this post Link to post
ZRomik 2 Posted March 28, 2019 Yes! It working! I mistaked and create event handler for wrong event. I am inattentive. Sorry and big thanks, Angus. And sorry for my english. Not my native language. Share this post Link to post
Angus Robertson 574 Posted March 28, 2019 25 minutes ago, ZRomik said: Yes! It working! I mistaked and create event handler for wrong event. I am inattentive. Sorry and big thanks, Angus. And sorry for my english. Not my native language. And I should not nave written code that allowed you to break the component, will fix it next week. Angus Share this post Link to post
ZRomik 2 Posted March 28, 2019 My token live 19 minutes. I must set property RefMinsPrior to 19? Share this post Link to post
ZRomik 2 Posted March 28, 2019 (edited) Angus, Can you do property TokenUrl for component TRestOAuth as published? Then component can be completely configured in design-time. Edited March 28, 2019 by ZRomik Share this post Link to post
ZRomik 2 Posted March 29, 2019 Today result of authorization Quote Failed to Generate App Token App Authorization Code: Pk0LCe2FYB6t_FMecf7-OJyX3W0RbvnOuItQ4-cvAv1zLel-mr0zfllEu62by6ec Success! You may close this page and return to app Maybe need add message about bad authorization? Split "RedirectMsg" to "ResdirectSuccMsg" and "RedirectBadMsg" as case. And how can handle error while authorization process? Share this post Link to post
Angus Robertson 574 Posted March 29, 2019 Sorry, busy doing other things that must be finished by month end, will look at this next week, Angus Share this post Link to post
Angus Robertson 574 Posted April 4, 2019 On 3/28/2019 at 6:17 PM, ZRomik said: Angus, Can you do property TokenUrl for component TRestOAuth as published? Then component can be completely configured in design-time. It is already published. Angus Share this post Link to post
Angus Robertson 574 Posted April 4, 2019 On 3/29/2019 at 5:55 AM, ZRomik said: Today result of authorization Maybe need add message about bad authorization? Split "RedirectMsg" to "ResdirectSuccMsg" and "RedirectBadMsg" as case. And how can handle error while authorization process? The Failed to Generate App Token message presumably originated from the OAuth2 server and was displayed in your browser, so our application can not see it. So no easy way to handle it. The component sees success by the browser redirecting to the local web server, but there is no redirect on failure. It is possible to embed a Microsoft Internet Explorer window into your application to handle OAuth2 and check responses, but this is not best security practice and some authentication servers may block use of embedded browsers. Angus Share this post Link to post
Angus Robertson 574 Posted April 5, 2019 SVN and the overnight zip are updated with a new version of TSslHttpRest heavily rewritten to be more user proof, also need changes to TSslHttpCli which was why it was originally written badly. But now the REST responses are available in both the OnRequestDone and OnRestRequestDone events. Angus Share this post Link to post
ZRomik 2 Posted April 8, 2019 On 4/5/2019 at 2:14 PM, Angus Robertson said: SVN and the overnight zip are updated with a new version of TSslHttpRest heavily rewritten to be more user proof, also need changes to TSslHttpCli which was why it was originally written badly. But now the REST responses are available in both the OnRequestDone and OnRestRequestDone events. Angus Where to find svn repository address? Share this post Link to post
FPiette 383 Posted April 8, 2019 You can find it on the download page at the wiki: http://wiki.overbyte.eu/wiki/index.php/ICS_Download#Version_Control_System François Piette Embarcadero MVP Share this post Link to post
ZRomik 2 Posted April 10, 2019 (edited) Thank you, François. Today I'm tested my app and found strange thing: handling OnRequestDone event of component TSslHttpCli raised EHttpException exception with message "OK". How I can delete this exception and resolve this issue? Edited April 10, 2019 by ZRomik Share this post Link to post
FPiette 383 Posted April 10, 2019 You should run your application under the debugger which will show where the exception occurs. This is what is needed to understand what happen. Share this post Link to post
ZRomik 2 Posted April 11, 2019 I resolved this issue. In OnBgException event handler I set field CanClose to True. And the error message does't appear anymore 1 Share this post Link to post
ZRomik 2 Posted April 12, 2019 (edited) Is there a way to know that the TRestOAuth component has updated the authorization token if autoupdate is set? Edited April 12, 2019 by ZRomik Share this post Link to post
Angus Robertson 574 Posted April 12, 2019 > Is there a way to know that the TRestOAuth component has updated the authorization token if autoupdate is set? Use the OnOAuthNewToken event and illustrated in the sample application. Angus Share this post Link to post
ZRomik 2 Posted July 12, 2019 Hello Again! OK, I need to get some data from server accross post-request. I write small app but always get error "Bad request". Can you see my code please? I use property ContentTypePost for set content-type as "application/json" post_test.zip Share this post Link to post
ZRomik 2 Posted August 8, 2019 Again trying send post-request as follow: if Not Assigned(FRcvStr) then FRcvStr := TMemoryStream.Create; if not Assigned(FSndStr) then FSndStr := TMemoryStream.Create; s := '{"names": ["Water"]}'; FSndStr.Write(s[1], Length(s)); cli1.SendStream := FSndStr; cli1.RcvdStream := FRcvStr; cli1.PostASync; So, If I use method Post then I get eror "BadRequest". If I use method PostAsync then I got answer; "{"error":"too few items for 'names', 'names' is required"}". Looks like data not sending to server. Share this post Link to post