My webcore app has a datamodule, a main form and several sub forms (created by the main form).
The application
creates the datamodule and initialises it
the datamodule creates the main form
the main form creates the default sub form
the user then selects several options on the defualt sub form and clicks submit
this calls Sphinx.Login
the user logs in successfully
the datamodule is recreated and initialised
the main form is created
But the TSphinxWebLogin.OnUserLoggedIn is not called
Also if I try to access the data returned in the JWT from the OnCreate of the datamodule it fails:
TypeError: Cannot read properties of null (reading 'AuthResult')
at Object.AuthResult (Sphinx.WebLogin.pas:172:21)
at Object.GetIdPayloadObject (Auth.Service.pas:136:35)
at Object.GetClaimValue (Auth.Service.pas:90:12)
at Object.UserId (Auth.Service.pas:155:13)
Still struggling with this. Wrote a test app pair and that was fine. I ran the test web app against the original server and that could login, with the same credentials.
I have checked the settings for Sphinx on the main webapp on the server and can't see anything different.
I have even created another app as a Sphinx client app that is identical to the test app (but with different id and redirect).
An attempted login from the main web app doesn't create a JWT, it looks as if the TokenBuilder isn't called. It is difficult to step through as there is so much middleware involved.
@wlandgraf is there a point I could break point to see where the decision might be made not to call the token builder?
I understand you could create a sample separated project that reproduces the issue (i.e., doesn't call the token builder?)
In that case can you send the sample project? Without us being able to debug it's hard to tell what's going on.
@wlandgraf is there a point I could break point to see where the decision might be made not to call the token builder?
First of all, what HTTP requests do you see happening from the browser? You see all the flow happening, the call to authorize endpoint, the call to token endpoint...?
When your web app is invoked back from the redirect URL (the index.html?state=... URL), somehow it's not reaching the TSphinxLogin component, either it's not loading, or it's not detecting that the URL is a redirect URL, something like that. That's probably why it's not calling the token endpoint.
Can you please check if these topics help you out somehow:
Especially the idea of calling Login method at all times so it not also redirects to the login page, but also process the token if the app is loading as a redirection back from login page.
I have structured the app so that when the user is logging in no other async processes are called until the OnUserLoggedIn event. I do this by setting a session var, so there should be nothing that sits in the way of the login process. However, it still fails, although at least it is calling crypto-js.min.js now
So this all works on my development machine, but when it's copied to the designers computer, it just doesn't call token. Same webcore js, same server, same sphinx server, same database.
@wlandgraf I think I have got to the bottom of this.
In my app I load a config file from the server which is called in
procedure TMainData.WebDataModuleCreate(Sender: TObject);
begin
Await(ConfigInit);
if FLoginState <> TLoginState.lisLoggingIn then
InitModule;
end;
procedure TMainData.ConfigInit;
begin
Await(LoadConfig);
if SessionValue[Login_Source] = '' then
FLoginSource := TLoginSource.lsNotSpecified
else
FLoginSource := TRttiEnumerationType.GetValue<TLoginSource>(SessionValue[Login_Source]);
if (SessionValue[Login_State] = '') then
FLoginState := TLoginState.lisNotLoggedIn
else
FLoginState := TRttiEnumerationType.GetValue<TLoginState>(SessionValue[Login_State]);
end;
And LoadConfig
procedure TMainData.LoadConfig;
var
Conn: TXDataWebConnection;
Response: IHttpResponse;
begin
Conn := TXDataWebConnection.Create(nil);
try
Response := TAwait.Exec<IHttpResponse>(Conn.SendRequestAsync(THttpRequest.Create('config/config.json')));
if Response.StatusCode = 200 then
begin
AppConfig.Load(Response.ContentAsText);
DataConnection.URL := AppConfig.BaseUrl;
SphinxLogin.Authority := AppConfig.AuthURL;
if AppConfig.SphinxClientId = '' then
SphinxLogin.ClientId := 'AlphaWebApp'
else
SphinxLogin.ClientId := AppConfig.SphinxClientId;
SphinxLogin.RedirectUri := SphinxRedirectUri;
end;
finally
Conn.Free;
end;
end;
But TOidcClient.CheckProviderInformation is called before any of this code. Hence, If I set the values at design time the login works, but if they are empty then this causes an exception before the config is processed.
Not sure why I haven't come across this in other apps.