/// <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;
                    }
                });
            }
        }
Пример #2
0
        public void CreateUserBinding_should_send_a_post_to_api_v2_user_bindings()
        {
            //given
            var userBinding = new UserBindingRequest()
            {
                TruCodeId      = System.Guid.NewGuid().ToString(),
                UserIdentifier = "taco123"
            };

            SetupMock(statusCode: HttpStatusCode.NoContent);

            //when
            sut.CreateUserBinding(userBinding);

            //then
            MockHttpClient.Verify(x => x.HandleRequest(
                                      It.Is <HttpRequestMessage>(req =>
                                                                 req.Method == HttpMethod.Post &&
                                                                 req.RequestUri == new System.Uri("https://jones.net/api/v2/user_bindings")
                                                                 //&& req.Content.ToString().Contains(userBinding.TruCodeId.ToString())
                                                                 ),
                                      It.IsAny <ApiCredentials>()
                                      ), Times.Exactly(1));
        }
 public async Task CreateUserBindingAsync(UserBindingRequest request)
 {
     await Post("/api/v2/user_bindings", request, _credentialProvider);
 }
 public void CreateUserBinding(UserBindingRequest request)
 {
     BlockAsyncForResult(
         CreateUserBindingAsync(request)
         );
 }