/// <summary>
        /// Binds the provided userIdentifier to the Trusona user that scanned the provided secure QR code ID.
        /// </summary>
        /// <param name="trusona">Trusona API.</param>
        /// <param name="userIdentifier">User identifier.</param>
        /// <param name="truCodeId">The secure QR code ID that the user scanned.</param>
        public static async Task CreateUserBinding(this Trusona trusona, string userIdentifier, string truCodeId)
        {
            UserBindingRequest request = new UserBindingRequest()
            {
                UserIdentifier = userIdentifier,
                TruCodeId      = truCodeId
            };

            try
            {
                await trusona.UserBindingService.CreateUserBindingAsync(request);
            }
            catch (TrusonaServiceException ex)
            {
                HandleServiceException(ex, (httpStatus, requestId) =>
                {
                    switch (httpStatus)
                    {
                    case HttpStatusCode.Conflict:
                        throw new UserAlreadyBoundException("A different userIdentifier has already been bound to this user.");

                    case (HttpStatusCode)424:
                        throw new TruCodeNotPairedException("The provided truCodeId was not scanned by a Trusona user and we could not determine which user to bind the identifier to.");

                    default:
                        DefaultErrorHandler(httpStatus, requestId);
                        break;
                    }
                });
            }
        }
        /// <summary>
        /// Create a user device binding in Trusona between a User and a Device, referenced by their identifiers. After creation,
        /// the binding will be inactive, and must be explicitly activated before the User can use the Device to complete
        /// Trusonafications.
        /// </summary>
        /// <returns>The user device.</returns>
        /// <param name="trusona">The Trusona API.</param>
        /// <param name="userIdentifier">User identifier.</param>
        /// <param name="deviceIdentifier">Device identifier.</param>
        public static async Task <UserDevice> CreateUserDevice(this Trusona trusona, string userIdentifier, string deviceIdentifier)
        {
            UserDeviceRequest request = new UserDeviceRequest()
            {
                UserIdentifier   = userIdentifier,
                DeviceIdentifier = deviceIdentifier
            };

            try
            {
                var response = await trusona.UserDeviceService.CreateUserDeviceAsync(request);

                return(trusona.mapper.Map <UserDevice>(response));
            }
            catch (TrusonaServiceException ex)
            {
                HandleServiceException(ex, (httpStatus, requestId) =>
                {
                    switch (httpStatus)
                    {
                    case HttpStatusCode.Conflict:
                        throw new DeviceAlreadyBoundException("A different user has already been bound to this device.");

                    case (HttpStatusCode)424:
                        throw new DeviceNotFoundException("The device you are attempting to bind to a user does not exist. The device will need to be re-registered with Trusona before attempting to bind it again.");

                    default:
                        DefaultErrorHandler(httpStatus, requestId);
                        break;
                    }
                });
                throw ex;
            }
        }
 public static async Task CancelTrusonafication(this Trusona trusona, Guid trusonaficationId)
 {
     try
     {
         await trusona.TrusonaficationService.CancelTrusonaficationAsync(trusonaficationId);
     }
     catch (TrusonaServiceException ex)
     {
         HandleServiceException(ex, DefaultErrorHandler);
         throw ex;
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Delete a user by their user identifier
 /// </summary>
 /// <param name="trusona">Trusona API.</param>
 /// <param name="userIdentifier">User identifier.</param>
 public static async Task DeleteUser(this Trusona trusona, string userIdentifier)
 {
     try
     {
         await trusona.UserService.DeleteUserAsync(userIdentifier);
     }
     catch (TrusonaServiceException ex)
     {
         HandleServiceException(ex, DefaultErrorHandler);
         throw ex;
     }
 }
        /// <summary>
        /// Gets a Trusonafication for a given Trusonafication ID.
        /// </summary>
        /// <returns>A Trusonafication</returns>
        /// <param name="trusona">Trusona API.</param>
        /// <param name="trusonaficationId">Trusonafication identifier.</param>
        public static async Task <Trusonafication> GetTrusonafication(this Trusona trusona, Guid trusonaficationId)
        {
            try
            {
                var response = await trusona.TrusonaficationService.GetTrusonaficationAsync(trusonaficationId);

                return(trusona.mapper.Map <Trusonafication>(response));
            }
            catch (TrusonaServiceException ex)
            {
                HandleServiceException(ex, DefaultErrorHandler);
                throw ex;
            }
        }
Ejemplo n.º 6
0
        public TrusonaTest()
        {
            this._mockConfiguration = new Mock <IConfiguration>();

            _mockConfiguration.Setup(x => x.EndpointUrl)
            .Returns(new Uri("https://jones.net"));

            _mockConfiguration.Setup(x => x.CredentialProvider)
            .Returns(new ApiCredentials(validToken, "jones"));

            this._mockHttpClient = new Mock <IHttpClientWrapper>();
            this._serviceFactory = new ServiceFactory(_mockConfiguration.Object, _mockHttpClient.Object);
            this.sut             = TestTrusonaFactory.InjectServiceFactory(_serviceFactory);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the device.
        /// </summary>
        /// <returns>The device.</returns>
        /// <param name="trusona">Trusona API.</param>
        /// <param name="deviceIdentifier">Device identifier.</param>
        public static async Task <Device> GetDevice(this Trusona trusona, string deviceIdentifier)
        {
            try
            {
                var response = await trusona.DeviceService.GetDeviceAsync(deviceIdentifier);

                var result = trusona.mapper.Map <Device>(response);
                return(result);
            }
            catch (TrusonaServiceException ex)
            {
                HandleServiceException(ex, DefaultErrorHandler);
                throw ex;
            }
        }
        /// <summary>
        /// Gets the identity document.
        /// </summary>
        /// <returns>The identity document.</returns>
        /// <param name="trusona">Trusona API.</param>
        /// <param name="id">Identifier.</param>
        public static async Task <IdentityDocument> GetIdentityDocument(this Trusona trusona, Guid id)
        {
            try
            {
                var response = await trusona.IdentityDocumentService.GetIdentityDocumentAsync(id);

                var result = trusona.mapper.Map <IdentityDocument>(response);
                return(result);
            }
            catch (TrusonaServiceException ex)
            {
                HandleServiceException(ex, DefaultErrorHandler);
                throw ex;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Get a TruCode that has been paired.
        /// </summary>
        /// <returns>The paired TruCode if it exists, or null.</returns>
        /// <param name="trusona">Trusona API.</param>
        /// <param name="id">The ID of the TruCode.</param>
        public static async Task <TruCode> GetPairedTruCode(this Trusona trusona, Guid id)
        {
            try
            {
                var response = trusona.TruCodeService.GetPairedTrucodeAsync(id);
                return(trusona.mapper.Map <TruCode>(await response));
            }
            catch (TrusonaServiceException ex)
            {
                if (ex.HttpResponse.StatusCode == HttpStatusCode.NotFound)
                {
                    return(null);
                }

                HandleServiceException(ex, DefaultErrorHandler);
                throw ex;
            }
        }
        /// <summary>
        /// Creates a Trusonafication and returns a TrusonaficationResult with the current status of the Trusonafication.
        /// See TrusonaficationStatus for the possible statuses.
        /// </summary>
        /// <returns>A TrusonaficationResult describing the current status of the Trusonafication.</returns>
        /// <param name="trusona">Trusona API.</param>
        /// <param name="trusonafication">A Trusonafication.</param>
        public static async Task <TrusonaficationResult> CreateTrusonafication(this Trusona trusona, Trusonafication trusonafication)
        {
            try
            {
                var response = await trusona.TrusonaficationService.CreateTrusonaficationAsync(
                    trusona.mapper.Map <TrusonaficationRequest>(trusonafication));

                var result = trusona.mapper.Map <TrusonaficationResult>(response);
                return(result);
            }
            catch (TrusonaServiceException ex)
            {
                if (ex.HttpResponse.StatusCode.Equals(422))
                {
                    // TODO: Additional logic here?
                }
                HandleServiceException(ex, DefaultErrorHandler);
                throw ex;
            }
        }
        /// <summary>
        /// Activates a user device binding in Trusona. After a binding is active, a user can respond to Trusonafications.
        /// Only call this method after you have verified the identity of the user.
        /// </summary>
        /// <returns>True if the device is activated.</returns>
        /// <param name="trusona">The Trusona API.</param>
        /// <param name="activationCode">Activation code.</param>
        public static async Task <bool> ActivateUserDevice(this Trusona trusona, string activationCode)
        {
            UserDeviceUpdateRequest request = new UserDeviceUpdateRequest()
            {
                Active = true
            };

            try
            {
                var response = await trusona.UserDeviceService.UpdateUserDeviceAsync(activationCode, request);

                var result = trusona.mapper.Map <UserDevice>(response);
                return(result.Active);
            }
            catch (TrusonaServiceException ex)
            {
                HandleServiceException(ex, DefaultErrorHandler);
                throw ex;
            }
        }
        /// <summary>
        /// Gets a TrusonaficationResult for a given Trusonafication ID.
        /// This will block until the Trusonafication is no longer IN_PROGRESS
        /// </summary>
        /// <returns>A TrusonaficationResult</returns>
        /// <param name="trusona">Trusona API.</param>
        /// <param name="trusonaficationId">Trusonafication identifier.</param>
        public static async Task <TrusonaficationResult> GetTrusonaficationResult(this Trusona trusona, Guid trusonaficationId)
        {
            try
            {
                var response = await trusona.TrusonaficationService.GetTrusonaficationAsync(trusonaficationId);

                var result = trusona.mapper.Map <TrusonaficationResult>(response);

                while (TrusonaficationStatus.IN_PROGRESS == result.Status)
                {
                    Thread.Sleep(trusona.pollingInterval);
                    response = await trusona.TrusonaficationService.GetTrusonaficationAsync(result.Id);

                    result = trusona.mapper.Map <TrusonaficationResult>(response);
                }

                return(result);
            }
            catch (TrusonaServiceException ex)
            {
                HandleServiceException(ex, DefaultErrorHandler);
                throw ex;
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Gets the web sdk config.
 /// </summary>
 /// <returns>The web sdk config.</returns>
 /// <param name="trusona">Trusona API.</param>
 public static string GetWebSdkConfig(this Trusona trusona)
 {
     return(trusona.WebSdkConfigService.GetWebSdkConfig());
 }
        /// <summary>
        /// Finds the identity documents.
        /// </summary>
        /// <returns>The identity documents.</returns>
        /// <param name="trusona">Trusona API.</param>
        /// <param name="userIdentifier">User identifier.</param>
        public static async Task <IEnumerable <IdentityDocument> > FindIdentityDocuments(this Trusona trusona, string userIdentifier)
        {
            try
            {
                var response = await trusona.IdentityDocumentService.FindIdentityDocumentsAsync(userIdentifier);

                var result = response.Select(r => trusona.mapper.Map <IdentityDocument>(r));
                return(result);
            }
            catch (TrusonaServiceException ex)
            {
                HandleServiceException(ex, DefaultErrorHandler);
                throw ex;
            }
        }