Beispiel #1
0
        async Task <Session> ProcessAuthenticationResponse(string authResponse)
        {
            try
            {
                // Decode auth response and initialise a new session
                var encodedRequest = BrowserAuthHelpers.GetRequestData(authResponse);
                var decodeResult   = await Session.DecodeIpcMessageAsync(encodedRequest);

                if (decodeResult.GetType() == typeof(AuthIpcMsg))
                {
                    Console.WriteLine("Auth Reqest Granted from Authenticator");

                    // Create session object
                    if (decodeResult is AuthIpcMsg ipcMsg)
                    {
                        // Initialise a new session
                        var session = await Session.AppRegisteredAsync(_appInfo.Id, ipcMsg.AuthGranted);

                        return(session);
                    }
                    else
                    {
                        Console.WriteLine("Invalid AuthIpcMsg");
                        throw new Exception("Invalid AuthIpcMsg.");
                    }
                }
                else
                {
                    Console.WriteLine("Auth Request is not Granted");
                    throw new Exception("Auth Request not granted.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
                throw ex;
            }
        }
Beispiel #2
0
        async Task AuthenticationWithBrowserAsync()
        {
            try
            {
                await ConfigureSession();

                // Generate and send auth request to safe-browser for authentication.
                var encodedReq = await BrowserAuthHelpers.GenerateEncodedAppRequestAsync(_appInfo);

                var url  = BrowserAuthHelpers.UrlFormat(_appInfo, encodedReq.Item2, true);
                var info = new System.Diagnostics.ProcessStartInfo
                {
                    UseShellExecute = true, // not default in netcore, so needs to be set
                    FileName        = url
                };
                System.Diagnostics.Process.Start(info);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
                throw ex;
            }
        }
Beispiel #3
0
 public static void WinDesktopUseBrowserAuth(AppInfo appInfo, string appPath)
 => BrowserAuthHelpers.RegisterAppProtocol(appInfo, appPath);