예제 #1
0
        public static async Task RequestAuthenticationAsync(bool isUnregistered = false)
        {
            try
            {
                string req;
                if (isUnregistered)
                {
                    (_, req) = await Session.EncodeUnregisteredRequestAsync(Constants.AppId);
                }
                else
                {
                    (_, req) = await GenerateEncodedAuthReqAsync();
                }
                var url         = UrlFormat.Format(Constants.AppId, req, true);
                var appLaunched = await DependencyService.Get <IPlatformService>().OpenUri(url);

                if (!appLaunched)
                {
                    await Application.Current.MainPage.DisplayAlert(
                        "Authorisation failed",
                        "The SAFE Authenticator app is required to authorise this application",
                        "OK");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw;
            }
        }
예제 #2
0
        public async Task <string> GenerateAppRequestAsync()
        {
            AuthReq authReq = new AuthReq
            {
                AppContainer = true,
                App          = new AppExchangeInfo {
                    Id = AppId, Scope = string.Empty, Name = "SAFE Todo App", Vendor = "MaidSafe.net Ltd"
                },
                Containers = new List <ContainerPermissions>
                {
                    new ContainerPermissions
                    {
                        ContName = "_publicNames",
                        Access   = { Insert = true, Update = true, Delete = true }
                    }
                }
            };

            (uint, string)encodedReq = await Session.EncodeAuthReqAsync(authReq);

            string formattedReq = UrlFormat.Format(AppId, encodedReq.Item2, true);

            Debug.WriteLine($"Encoded Req: {formattedReq}");
            return(formattedReq);
        }
        public void SendRequest(string encodedRequest, bool isUnregistered)
        {
            var formattedReqUrl = UrlFormat.Format(Constants.AppId, encodedRequest, true);

            Debug.WriteLine($"Encoded Req : {formattedReqUrl}");

            Device.BeginInvokeOnMainThread(() => { Device.OpenUri(new Uri(formattedReqUrl)); });
        }
        public async Task ProcessNonMockAuthentication()
        {
            // Send encoded AuthReq to SAFE Authenticator using Uri
            var encodedAuthReq = await GenerateEncodedAuthReqAsync();

            var url = UrlFormat.Format(Constants.AppId, encodedAuthReq.Item2, true);

            Device.BeginInvokeOnMainThread(() => { Device.OpenUri(new Uri(url)); });
        }
예제 #5
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);
        }
예제 #6
0
        public async Task RequestAuthenticationAsync(bool isUnregistered = false)
        {
            try
            {
                App.PendingRequest = true;

                var filePath = Path.Combine(ConfigFilePath, _defaultNodeConnectionFileName);
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }

                string req;
                if (isUnregistered)
                {
                    (_, req) = await Session.EncodeUnregisteredRequestAsync(Constants.AppId);
                }
                else
                {
                    (_, req) = await GenerateEncodedAuthReqAsync();
                }
                var url         = UrlFormat.Format(Constants.AppId, req, true);
                var appLaunched = await DependencyService.Get <IPlatformService>().OpenUri(url);

                if (!appLaunched)
                {
                    await Application.Current.MainPage.DisplayAlert(
                        ErrorConstants.AuthenticationFailedTitle,
                        ErrorConstants.AuthenticatorAppNotFoundMsg,
                        "OK");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw;
            }
        }