Cannot use the Sphinx login in a Webcore applicaion

Hello,
I have a Sphinx service that works very well in desktop mode, and I'm trying to implement a TMS webcore version, starting with a small demo. But the Sphinx login screen never starts.
Here are the parameters used:

At the server side:

Client := SphinxConfig1.Clients.Add;
Client.ClientId := 'web';
Client.DisplayName := 'Web test';
Client.RedirectUris.Add('http://localhost:8000/Project1/');
Client.RequireClientSecret := False;
Client.AllowedGrantTypes := [TGrantType.gtAuthorizationCode];
Client.ValidScopes.Add('openid');
Client.ValidScopes.Add('email');

And at the client side:

SphinxWebLogin1.Authority := 'https://My.Sphinx.Url';
SphinxWebLogin1.ClientId := 'web';
SphinxWebLogin1.Scope := 'openid email';
SphinxWebLogin1.Login;

Please could you help me to see what's wrong?
Thanks

Dear @GHAZALI_Abdesselam, please refer to:

Hello Wagner,

I found my error after a lot of searching. I didn't add cryptojs library (it would be easier to notify this in the sphinx manual).
Now, after successfully login, I get an 404 error message: "page not found : http://localhost:8000/Project1/?state=xxxxxxx&code=yyyyyyy
I am forgetting something again!
Remark: Setting Application.HandleOAuth to true of false do not change anything, in my case.

Kind regards;

If you are getting a 404 error, maybe your redirect URL is not correct. Is that URL your TMS Web Core application URL?

To avoid confusion with the name Project1, I create a new project "MyWebTest" from "New/Other.../TMS WEB/TMS WEB Application" wizard.
The Sphinx service is located at my production server (HTTPS), and the project runs from localhost (Windows PC with Delphi).So 2 different domains. Cors middleware is added to Sphinx Server.
I don't know if the redirect URL syntax is correctly specified : http://localhost:8000/MyWebTest/
SphinxWebLogin1.RedirectUri := 'http://localhost:8000/MyWebTest/'; // At client side
Client.RedirectUris.Add('http://localhost:8000/MyWebTest/'); // At Sphinx side
The Web application start page is 'http://localhost:8000/MyWebTest/MyWebTest.html'
I am a bit confused with the error at console:
GET:>http://localhost:8000/MyWebTest/?state=XXXXXXXXXX&code=YYYYYYYYY 404 not found
Thank you

Try set the RedirectUri to http://localhost:8000/MyWebTest/MyWebTest.html

Hi Wagner,

Sorry for my late reply.

With redirectUri= http://localhost:8000/MyWebTest/MyWebTest.html it works, but not the first time. Let me explain:
When I run SphinxWebLogin1.Login, the login screen opens and my credentials are accepted, but the OnUserLogin event don't run. When I run SphinxWebLogin1.Login again, the login screen doesn't reopen (I'm already logged in) but the OnUserLogin event does run.

Thank you for help.

Do you still have the HandleOAuth set? That's a side effect of not having it set to False.

I set it on the first line of project source MyWebTest.dpr:

Application.HandleOAuth := False;

Do you see any errors in browser console the first time the application loads?

As a workaround, please try to set all properties and events in TSphinxWebLogin component from code, instead of setting it from the object inspector, and see if it solves the issue.

I don't get any error message on browser console. I get the same behaviour on Firefox, Chrome and Edge browsers (Windows 11)
I moved all properties and events from object inspector and set theme from code on FormCreate procedure.

I'm afraid you will have to create a small project reproducing the issue then, and please send to us.
Have you run the Sphinx demo, does it work for you?

Sphinx demo runs successfully with the web demo client included only (in the WebClientFiles directory).

I added the following lines to the Sphinx demo server:

  // Create mywebtest client
  Client := SphinxConfig1.Clients.Add;
  Client.ClientId := 'mywebtest';
  Client.DisplayName := 'My Web test App';
  Client.RedirectUris.Add('http://localhost:8000/MyWebTest/MyWebTest.html');
  Client.RequireClientSecret := False;
  Client.AllowedGrantTypes := [TGrantType.gtAuthorizationCode];
  Client.ValidScopes.Add('openid');
  Client.ValidScopes.Add('email');

MyWebTest project is attached 
[MyWebTest.zip|attachment](upload://nxXZ2MbVt2wOgQT9UCSUfAsbYbz.zip) (1.7 MB)
 
TMS Web Core version: 2.2.3.2 
TMS Sphinx version: 1.4.0.0
Delphi 11.3 Patch 1

Hi @GHAZALI_Abdesselam, there is no attachment in the message.
Also, please provide the exact steps to reproduce the issue - i.e, what should I do with your project?

Hello,

I'm sorry. Here is the zip file: MyWebTest.zip (986.9 KB)

The project is very simple, with just a WebButton to execute the code to connect and a Webmemo to display the access token returned. I didn't send the server since I use the Sphinx server provided by the demo with specific client added:

  // Create mywebtest client
  Client := SphinxConfig1.Clients.Add;
  Client.ClientId := 'mywebtest';
  Client.DisplayName := 'My Web test App';
  Client.RedirectUris.Add('http://localhost:8000/MyWebTest/MyWebTest.html');
  Client.RequireClientSecret := False;
  Client.AllowedGrantTypes := [TGrantType.gtAuthorizationCode];
  Client.ValidScopes.Add('openid');
  Client.ValidScopes.Add('email');

Thank you

In this specific case, you have to revert and set the properties in the object inspector. Then it will work automatically, because the properties would be already set when the application reloads.

If you want to keep the properties set from code, then you can simply call Login method again, it will do the automation and call the event if user is logged in.

Hello,

It works. Thank you.

Kind regards

1 Like