public async Task HandleUrlActivationAsync(string url)
        {
            try
            {
                // Decode auth response and Initialise a new session
                var encodedRequest = UrlFormat.GetRequestData(url);
                var decodeResult   = await Session.DecodeIpcMessageAsync(encodedRequest);

                if (decodeResult.GetType() == typeof(AuthIpcMsg))
                {
                    var ipcMsg = decodeResult as AuthIpcMsg;

                    if (ipcMsg != null)
                    {
                        _session = await Session.AppRegisteredAsync(Constants.AppId, ipcMsg.AuthGranted);

                        DialogHelper.ShowToast("Auth Granted", DialogType.Success);
                        MessagingCenter.Send(this, MessengerConstants.NavigateToItemPage);
                    }
                }
                else
                {
                    Debug.WriteLine("Auth Req is not Auth Granted");
                }
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", $"Description: {ex.Message}", "OK");
            }
        }
Esempio n. 2
0
        internal async Task HandleUrlActivationAsync(string encodedUri)
        {
            try
            {
                if (await HandleUnregisteredAppRequest(encodedUri))
                {
                    return;
                }

                if (_authenticator == null)
                {
                    AuthenticationReq = encodedUri;
                    if (!_sessionConfig.KeepAlive)
                    {
                        //var response = await Application.Current.MainPage.DisplayAlert(
                        //    "Login Required",
                        //    "An application is requesting access, login to authorise",
                        //    "Login",
                        //    "Cancel");
                        //if (response)
                        //{
                        //    MessagingCenter.Send(this, MessengerConstants.NavPreviousPage);
                        //}
                    }
                    return;
                }

                //if (Connectivity.NetworkAccess == NetworkAccess.Internet)
                //{
                await CheckAndReconnect();

                //}

                var encodedReq   = UrlFormat.GetRequestData(encodedUri);
                var decodeResult = await _authenticator.DecodeIpcMessageAsync(encodedReq);

                var decodedType = decodeResult.GetType();
                if (decodedType == typeof(IpcReqError))
                {
                    var error = decodeResult as IpcReqError;
                    throw new FfiException(error.Code, error.Description);
                }
                else
                {
                    //MessagingCenter.Send(this, MessengerConstants.NavPreviousPage);
                    //var requestPage = new RequestDetailPage(encodedUri, decodeResult);
                    //await Application.Current.MainPage.Navigation.PushPopupAsync(requestPage);
                }
            }
            catch (FfiException ex)
            {
                var errorMessage = Utilities.GetErrorMessage(ex);
                //await Application.Current.MainPage.DisplayAlert("Authorisation Error", errorMessage, "OK");
            }
            catch (Exception ex)
            {
                //await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK");
            }
        }
Esempio n. 3
0
        public async Task ProcessAuthenticationResponseAsync(string url)
        {
            try
            {
                MessagingCenter.Send(this, MessageCenterConstants.ProcessingAuthResponse);
                var encodedResponse = UrlFormat.GetRequestData(url);
                var decodeResponse  = await Session.DecodeIpcMessageAsync(encodedResponse);

                var decodedResponseType = decodeResponse.GetType();
                if (decodedResponseType == typeof(UnregisteredIpcMsg))
                {
                    if (decodeResponse is UnregisteredIpcMsg ipcMsg)
                    {
                        App.AppSession = await Session.AppConnectAsync(Constants.AppId, encodedResponse);

                        MessagingCenter.Send(this, MessageCenterConstants.Authenticated, encodedResponse);
                    }
                }
                else if (decodedResponseType == typeof(AuthIpcMsg))
                {
                    if (decodeResponse is AuthIpcMsg ipcMsg)
                    {
                        using (UserDialogs.Instance.Loading(Constants.ConnectingProgressText))
                        {
                            Session session = await Session.AppConnectAsync(Constants.AppId, encodedResponse);

                            AppService.InitialiseSession(session);
                        }
                    }
                }
            }
            catch (FfiException ex)
            {
                Logger.Error(ex);
                if (ex.ErrorCode != -106)
                {
                    if (ex.Message.Contains("AuthDenied"))
                    {
                        await Application.Current.MainPage.DisplayAlert(
                            ErrorConstants.AuthenticationFailedTitle,
                            ErrorConstants.RequestDeniedMsg,
                            "OK");
                    }
                    else
                    {
                        await Application.Current.MainPage.DisplayAlert(
                            ErrorConstants.AuthenticationFailedTitle,
                            ErrorConstants.AuthenticationFailedMsg,
                            "OK");
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                await Application.Current.MainPage.DisplayAlert("Authentication", "Authentication Failed", "OK");
            }
        }
Esempio n. 4
0
        public async Task <string> HandleUrlActivationAsync(string encodedUri)
        {
            try
            {
                if (_authenticator == null)
                {
                    return(null);
                }

                await CheckAndReconnect();

                var encodedReq   = UrlFormat.GetRequestData(encodedUri);
                var decodeResult = await _authenticator.DecodeIpcMessageAsync(encodedReq);

                var decodedType = decodeResult.GetType();
                if (decodedType == typeof(AuthIpcReq))
                {
                    var authReq = decodeResult as AuthIpcReq;
                    Debug.WriteLine($"Decoded Req From {authReq?.AuthReq.App.Name}");
                    var isGranted = true;
                    //  await Application.Current.MainPage.DisplayAlert(
                    //"Auth Request",
                    //$"{authReq?.AuthReq.App.Name} is requesting access",
                    //"Allow",
                    //"Deny");
                    var encodedRsp = await _authenticator.EncodeAuthRespAsync(authReq, isGranted);

                    var formattedRsp = UrlFormat.Format(authReq?.AuthReq.App.Id, encodedRsp, false);
                    Debug.WriteLine($"Encoded Rsp to app: {formattedRsp}");
                    //Device.BeginInvokeOnMainThread(() => { Device.OpenUri(new Uri(formattedRsp)); });
                    return(formattedRsp);
                }
                else if (decodedType == typeof(IpcReqError))
                {
                    var error = decodeResult as IpcReqError;
                    Debug.WriteLine("Auth Request", $"Error: {error?.Description}", "Ok");
                }
                else
                {
                    Debug.WriteLine("Decoded Req is not Auth Req");
                }
            }
            catch (Exception ex)
            {
                var errorMsg = ex.Message;
                if (ex is ArgumentNullException)
                {
                    errorMsg = "Ignoring Auth Request: Need to be logged in to accept app requests.";
                }

                Debug.WriteLine("Error", errorMsg, "OK");
            }

            return(null);
        }
        public async Task ProcessResponseAsync(string encodedResponse)
        {
            try
            {
                var encodedRequest = UrlFormat.GetRequestData(encodedResponse);
                var decodeResult   = await Session.DecodeIpcMessageAsync(encodedRequest);

                var decodeResultType = decodeResult.GetType();
                if (decodeResultType == typeof(AuthIpcMsg))
                {
                    Debug.WriteLine("Received Auth Granted from Authenticator");
                    // Update auth progress message
                    var ipcMsg = decodeResult as AuthIpcMsg;
                    await Application.Current.MainPage.DisplayAlert("Auth Request", $"Request granted", "OK");

                    var session = await Session.AppRegisteredAsync(Constants.AppId, ipcMsg.AuthGranted);

                    DependencyService.Get <SafeAppService>().InitialiseSession(session, false);
                    MessagingCenter.Send(this, "UpdateUI");
                }
                else if (decodeResultType == typeof(ContainersIpcMsg))
                {
                    // Get container response and refresh container
                    var ipcMsg = decodeResult as ContainersIpcMsg;
                    await Application.Current.MainPage.DisplayAlert("Container Request", $"Request granted", "OK");

                    await DependencyService.Get <SafeAppService>().RefreshContainersAsync();
                }
                else if (decodeResultType == typeof(ShareMDataIpcMsg))
                {
                    // Get Share MData response
                    var ipcMsg = decodeResult as ShareMDataIpcMsg;
                    await Application.Current.MainPage.DisplayAlert("ShareMData Request", $"Request granted", "OK");
                }
                else if (decodeResultType == typeof(UnregisteredIpcMsg))
                {
                    //Create session object
                    var ipcMsg = decodeResult as UnregisteredIpcMsg;
                    await Application.Current.MainPage.DisplayAlert("Unregistred Request", $"Request granted", "OK");

                    var session = await Session.AppUnregisteredAsync(ipcMsg.SerialisedCfg);

                    DependencyService.Get <SafeAppService>().InitialiseSession(session, true);
                    MessagingCenter.Send(this, "UpdateUI");
                }
                else
                {
                    await Application.Current.MainPage.DisplayAlert("Error", $"Request not granted", "OK");
                }
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", $"Description: {ex.Message}", "OK");
            }
        }
Esempio n. 6
0
        async Task <bool> HandleUnregisteredAppRequest(string encodedUri)
        {
            var encodedReq    = UrlFormat.GetRequestData(encodedUri);
            var udecodeResult = await AuthSession.UnRegisteredDecodeIpcMsgAsync(encodedReq);

            if (udecodeResult.GetType() == typeof(UnregisteredIpcReq))
            {
                //var requestPage = new RequestDetailPage(encodedUri, udecodeResult);
                //await Application.Current.MainPage.Navigation.PushPopupAsync(requestPage);
                return(true);
            }
            return(false);
        }