- Redirect to browser:
public ICommand SignInCommand { get; }
public LoginViewModel(){
...
SignInCommand = new RelayCommand(SignIn);
private void SignIn()
{
loginUrl.OpenLink();
close app code
....
public static void OpenLink(this string link)
{
var psi = new ProcessStartInfo
{
FileName = link,
UseShellExecute = true
};
Process.Start(psi);
}
- Getting token on start up in the App.xaml.cs.
protected override void OnStartup(StartupEventArgs e)
{
...
base.OnStartup(e);
if (Environment.GetCommandLineArgs().Length > 1)
{
GlobalSettings.Instance.AppToken = Environment.GetCommandLineArgs()[1];
_dialogService?.Show(ViewName.MAIN);
}
else
{
_dialogService?.Show(ViewName.LOGIN);
}
- Registry file (installer set it up) when a user clicks a link in the webapp the wpf app is started and get a token via Environment.GetCommandLineArgs() function.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\boseaudiodriver]
@="URL:webapp"
"URL Protocol"=""
"UseOriginalUrlEncoding"=dword:00000001
[HKEY_CLASSES_ROOT\webapp\DefaultIcon]
@="\"C:\Program Files\MyWPFApp\MyWPFApp.exe\",1"
[HKEY_CLASSES_ROOT\webapp\shell]
[HKEY_CLASSES_ROOT\webapp\shell\open]
[HKEY_CLASSES_ROOT\webapp\shell\open\command]
@="\"C:\Program Files\MyWPFApp\MyWPFApp.exe\" \"--url=%1\""