Hi,
We need to create a TOKEN (‘https://{HOSTNAME}/idp/connect/token’) from a smart client plugin. How can you know the username and password of the current user to send an API call or can you get a TOKEN in some other way?
Also, is it possible to create a TOKEN for a Windows user? I get error “INVALID_GRANT”, (for basic user works fine).
many thanks
The Smart Client is already logged in which also means it has a token.
You can in a plugin get the IDP Token like this..
var loginSettings = VideoOS.Platform.Login.LoginSettings.GetLoginSettings(EnvironmentManager.Instance.MasterSite.ServerId);
var idpToken = loginSettings.IdentityTokenCache.Token;
Yes, I saw this answer in another post, I tried to write it in mine and it is not correct
, I am using version 2023 R2
GetLoginSettings is not recognized in the LoginSettings class but only in the LoginSettingsCache class
And the variable loginSettings - IdentityTokenCache does not recognize anything but a TOKEN in loginSettings
my code :
var loginSettings = VideoOS.Platform.Login.GetLoginSettingsCache.GetLoginSettings(EnvironmentManager.Instance.MasterSite.ServerId);
var myToken = loginSettings.Token;
and a TOKEN is returned to me, I use the TOKEN to call an API and an error is returned to me that the TOKEN is invalid
By the way, I see that this TOKEN looks different from the TOKEN I receive by username and password.
I would appreciate the help how do I get a good TOKEN to use for API calls
Just to clarify: loginSettings.Token is legacy Milestone token and can only be used with specific services. IdentityTokenCache will provide oauth token which is valid for oauth web services.
I tried to write it in mine and it is not correct.
TOKEN is returned to me, I use the TOKEN to call an API and an error is returned to me that the TOKEN is invalid
By the way, I see that this TOKEN looks different from the TOKEN I receive by username and password.
I would appreciate the help how do I get a good TOKEN to use for API calls
Please try the one I mention above.
Allow me to explain (in other words compared to Peter):
loginSettings.Token; -is a legacy token which has always been in XProtect and is still used for some of the interfaces.
loginSettings.IdentityTokenCache.Token; -is a IDP token later introduced. Supported in XProtect 2021R1 or later. This token is used by the new Rest APIs.
loginSettings.IdentityTokenCache is Unknown.
So that explains why you tried the other one.. It is a real mystery. Your code is a Smart Client plugin, correct? The Smart Client is version 2023R2, correct? The VideoOS.Platform you use when building the plugin is the newest (NuGet), correct?
Please explain where the code is executed, what class is this in?
Do your code look different than the two lines of mine above?
My code is a Smart Client plugin.
The Smart Client is version 2023R2
The code is in a normal class, inside a function
Does it look the same as the two lines above
How do I know that the VideoOS.Platform I’m using when building the plugin is the latest (NuGet)?
What I am asking is if the class is like (Xxx : ViewItemWpfUserControl) than that is one option, tell me the details and I can attempt to reproduce.
Look at your references in Visual Studio, does it list a MilestoneSystems.VideoOS.Platform nuget or does it list a VideoOS.Platform dll? Further you can then do a “Management NuGet Packages…” and see what version,
It works,
I saw that the version was not updated, I updated the VideoOS.Platform.dll file (to 2023 R2 version) and it works!
I am use with SidePanelUserControl and not ViewItemWpfUserControl, it ok ?
Thanks.
Thank you for the good news that you made it work!
For my part it was a question what class it was and ViewItemWpfUserControl was given from me as one example, so it is OK that you use SidePanelUserControl. I only asked as a step in troubleshooting, perhaps knowing the details would reveal an issue I could reproduce in the Milestone test labs.
As a general tip from me; so many issues come from having a mix of new and old dependent files, next time you switch to a newer version of the NuGets make sure to remove everything old!