Hi I am new to Sphinx (and BIZ). I have just bought the components a few weeks ago. Used the XData etc. to change an existing application to a web accessible application. Now come the authentication. I have gone through all the initial documents and created the necessary modules to run the server (to supply the database) and the login portion on the application.
I call the login from SphinxLogin component and it does the necessary web pages as described in the documentation. On the user being logged in I checked to see if the who logged in user is and then apply the necessary UserId to the application to filter data as needed.
However, I when I tried to get the user ID I get an access error.
If SphinxLogin1.IsLoggedIn then
begin
If Args.LoginResult.Profile <> nil then
begin
LoginEdit.text := Args.LoginResult.Profile.Source['user'].AsString;
UserName.text:= Args.LoginResult.Profile.Source['Preferred_UserName'].AsString;
UserEmail.text := Args.LoginResult.Profile.Email;
//Connects to web XData module. Checks the user is a valid user etc.
end
else
begin
MessageDlg('Failed Login!', mtWarning,[mbOk],0);
end;
end;
end
else
begin
MessageDlg('There is no login ID found for the Login!',mtInformation,[mbOk],0);
Exit;
end;
end;
I have checked out the code from Mark van der Berg. It helped me greatly, thanks to Mark he has shown me a lot of new tricks.
I did use that code as described, note the firs 3 lines of example code I posted. This is identical to the lines that were posted in your post that was suggested by Wagner. In run time I get an access error. That means that the code is not loaded or the procedure is not able to access it. I did try and add the token as you explained in your post think that the claims are not registered/added. But that too gave errors that I did not understand, and why it would not add those claims. I can't remember what errors they were and will need to go back to the service module and try and add them again.
After some more testing, what I want to get back is the UserId string. The code that was suggested does not return the username per say. If the user logged in as Ass001. I need to read that string once the user is logged in. The code suggested is ...Profile.subject but this does bring back the UserID except for a string value that (I assume) represents the UserID. Could I add a claim that will send the UserId in plain text (e.g. Ass001).
But that's that code Mark's suggested topic does. If you need the internal user id, you use Info.Profile.Subject. If you need the user name, you use Info.Profile.PreferredUserName.
Thanks for your reply. Ah, it makes sense, okay I just need to figure out how to call that parameter. I only just started with this set of components, so my understanding is a bit limited. If necessary, I will contact Mark if that is possible. At present when I call for that parameter, I get an access error i.e. the application does not have access to that property or parameter.
I see that he has a procedure that writes or sets the value which I assume is add or set in the server application. I will need to go through the code and see how it is called on the server side, but it may be missing in the example as he added that comment after he wrote/developed the example.
Perhaps, could let me know where you would add/set the PreferredUserName on the server side and how it is called.
I got it sorted, thank you. It is functioning as expected. I need to get my head around the email authentication. I will be following what Mark has proposed. We are getting there. Need the time to test the functionality.
Just to ask. In the example we used an SQLite database (created in runtime). Is it possible to create all the same tables and field names in an MSSQL database and get Sphinx to use that DB instead?