コード例 #1
0
        public ActionResult RefreshToken([FromBody] UpdateTokenRequest updateTokenRequest)
        {
            SecurityToken securityToken = null;
            // アクセストークンからClaimsPrincipalを取得
            ClaimsPrincipal cp = this._jwtHelper.ValidateAccessToken(updateTokenRequest.AccessToken, out securityToken);

            if (cp == null)
            {
                return(BadRequest(ModelState));
            }
            // ClaimsPrincipalからID(ユーザID)を取得
            var id = cp.Claims.First(c => c.Type == System.Security.Claims.ClaimTypes.NameIdentifier).Value;
            // ユーザIDからUserオブジェクトを取得
            var user = Models.User.GetByID(id);

            // リフレッシュトークンの妥当性をチェック
            if (user == null || user.RefreshToken != updateTokenRequest.RefreshToken)
            {
                return(BadRequest(ModelState));
            }

            // トークンを更新
            var authToken = this._jwtHelper.GenerateAuthToken(user);

            user.RefreshToken = authToken.RefreshToken;

            return(this.CreateJsonContentResult(authToken));;
        }
コード例 #2
0
        /// <summary>
        /// Resource /{merchantId}/tokens/{tokenId}
        /// <a href="https://developer.globalcollect.com/documentation/api/server/#__merchantId__tokens__tokenId__put">Update token</a>
        /// </summary>
        /// <param name="tokenId">string</param>
        /// <param name="body">UpdateTokenRequest</param>
        /// <param name="context">CallContext</param>
        /// <returns>void</returns>
        /// <exception cref="ValidationException">if the request was not correct and couldn't be processed (HTTP status code BadRequest)</exception>
        /// <exception cref="AuthorizationException">if the request was not allowed (HTTP status code Forbidden)</exception>
        /// <exception cref="IdempotenceException">if an idempotent request caused a conflict (HTTP status code Conflict)</exception>
        /// <exception cref="ReferenceException">if an object was attempted to be referenced that doesn't exist or has been removed,
        ///            or there was a conflict (HTTP status code NotFound, Conflict or Gone)</exception>
        /// <exception cref="GlobalCollectException">if something went wrong at the GlobalCollect platform,
        ///            the GlobalCollect platform was unable to process a message from a downstream partner/acquirer,
        ///            or the service that you're trying to reach is temporary unavailable (HTTP status code InternalServerError, BadGateway or ServiceUnavailable)</exception>
        /// <exception cref="ApiException">if the GlobalCollect platform returned any other error</exception>
        public async Task Update(string tokenId, UpdateTokenRequest body, CallContext context = null)
        {
            IDictionary <string, string> pathContext = new Dictionary <string, string>();

            pathContext.Add("tokenId", tokenId);
            string uri = InstantiateUri("/{apiVersion}/{merchantId}/tokens/{tokenId}", pathContext);

            try
            {
                await _communicator.Put <object>(
                    uri,
                    ClientHeaders,
                    null,
                    body,
                    context);
            }
            catch (ResponseException e)
            {
                object errorObject;
                switch (e.StatusCode)
                {
                default:
                    errorObject = _communicator.Marshaller.Unmarshal <ErrorResponse>(e.Body);
                    break;
                }
                throw CreateException(e.StatusCode, e.Body, errorObject, context);
            }
        }
コード例 #3
0
        public void UpdateTokenDeviceName()
        {
            string new_device_name = "My home computer";

            var token  = testServer.GetAccessToken().Token.ToShortToken();
            var client = testServer.GetJsonClient();
            var url    = new UpdateTokenRequest().ToUrl("PUT");
            var req    = new AccessTokenDto {
                TokenPart  = token,
                DeviceName = new_device_name
            };
            var service_url = testServer.ListenUrl + url;

            client.Put <AccessTokenDto> (service_url, req);

            // check that the token has been updated
            var get_url = new GetTokenRequest()
            {
                Username = RainyTestServer.TEST_USER
            }.ToUrl("GET");
            var get_service_url          = testServer.ListenUrl + get_url;
            List <AccessTokenDto> tokens = client.Get <List <AccessTokenDto> > (get_service_url);
            var updated_token            = tokens.First(t => token == t.TokenPart);

            Assert.AreEqual(new_device_name, updated_token.DeviceName);
        }
        public void Execute(int tokenId, UpdateTokenRequest request)
        {
            var response = _tokensGateway.UpdateToken(tokenId, request.Enabled);

            if (response == null)
            {
                throw new TokenRecordNotFoundException();
            }
        }
 /// <summary>
 /// Medota odpowiedzialna za odświeżenie tokenu co godzinę.
 /// </summary>
 /// <returns>Zwraca nowy token w formie stringa.</returns>
 public static string RefreshToken()
 {
     var updateTokenRequest = new UpdateTokenRequest();
     UpdateTokenResponse updateTokenResponse =
         WebServiceConnection.SendPost<UpdateTokenRequest, UpdateTokenResponse>(updateTokenRequest,
             "token/update").Result;
     Logs.WriteErrorLog("Nowy token: " + updateTokenResponse.Token);
     WriteLastTokenToFile(updateTokenResponse.Token);
     return updateTokenResponse.Token ?? null;
 }
        /// <summary>
        /// Medota odpowiedzialna za odświeżenie tokenu co godzinę.
        /// </summary>
        /// <returns>Zwraca nowy token w formie stringa.</returns>
        public static string RefreshToken()
        {
            var updateTokenRequest = new UpdateTokenRequest();
            UpdateTokenResponse updateTokenResponse =
                WebServiceConnection.SendPost <UpdateTokenRequest, UpdateTokenResponse>(updateTokenRequest,
                                                                                        "token/update").Result;

            Logs.WriteErrorLog("Nowy token: " + updateTokenResponse.Token);
            WriteLastTokenToFile(updateTokenResponse.Token);
            return(updateTokenResponse.Token ?? null);
        }
コード例 #7
0
        public async void Example()
        {
#pragma warning disable 0168
            using (Client client = GetClient())
            {
                Address billingAddress = new Address();
                billingAddress.AdditionalInfo = "b";
                billingAddress.City           = "Monument Valley";
                billingAddress.CountryCode    = "US";
                billingAddress.HouseNumber    = "13";
                billingAddress.State          = "Utah";
                billingAddress.Street         = "Desertroad";
                billingAddress.Zip            = "84536";

                CompanyInformation companyInformation = new CompanyInformation();
                companyInformation.Name = "Acme Labs";

                PersonalNameToken name = new PersonalNameToken();
                name.FirstName     = "Wile";
                name.Surname       = "Coyote";
                name.SurnamePrefix = "E.";

                PersonalInformationToken personalInformation = new PersonalInformationToken();
                personalInformation.Name = name;

                CustomerToken customer = new CustomerToken();
                customer.BillingAddress      = billingAddress;
                customer.CompanyInformation  = companyInformation;
                customer.MerchantCustomerId  = "1234";
                customer.PersonalInformation = personalInformation;

                CardWithoutCvv cardWithoutCvv = new CardWithoutCvv();
                cardWithoutCvv.CardNumber     = "4567350000427977";
                cardWithoutCvv.CardholderName = "Wile E. Coyote";
                cardWithoutCvv.ExpiryDate     = "1299";
                cardWithoutCvv.IssueNumber    = "12";

                TokenCardData data = new TokenCardData();
                data.CardWithoutCvv = cardWithoutCvv;

                TokenCard card = new TokenCard();
                card.Customer = customer;
                card.Data     = data;

                UpdateTokenRequest body = new UpdateTokenRequest();
                body.Card             = card;
                body.PaymentProductId = 1;

                await client.Merchant("merchantId").Tokens().Update("tokenId", body);
            }
#pragma warning restore 0168
        }
コード例 #8
0
        public IActionResult UpdateToken(int tokenId, [FromBody] UpdateTokenRequest request)
        {
            try
            {
                _updateTokenValidity.Execute(tokenId, request);
            }
            catch (TokenRecordNotFoundException)
            {
                return(NotFound("A token for this ID could not be found"));
            }

            return(NoContent());
        }
        public async Task <IActionResult> Update(UpdateTokenRequest request)
        {
            if (request.Id == Guid.Empty)
            {
                return(BadRequest("El Id no puede tener un valor vacio."));
            }

            if (string.IsNullOrWhiteSpace(request.Token))
            {
                return(BadRequest("El Token no puede estar vacio."));
            }

            if (string.IsNullOrWhiteSpace(request.RefreshToken))
            {
                return(BadRequest("El RefreshToken no puede estar vacio."));
            }

            if (!request.Expires.HasValue)
            {
                return(BadRequest("Debe ingresar una fecha de expiración."));
            }

            if (string.IsNullOrWhiteSpace(request.TokenType))
            {
                return(BadRequest("El TokenType no puede estar vacio."));
            }

            var responseToken = await _tokenService.Get(request.Id);

            Token token = responseToken.Result;

            token.Value        = request.Token;
            token.RefreshToken = request.RefreshToken;
            token.Expires      = request.Expires.Value;
            token.TokenType    = request.TokenType;

            return(Ok(await _tokenService.Update(token)));
        }
コード例 #10
0
        /// <summary>
        /// Metoda logowania do WebServisu wywoływana na starcie
        /// </summary>
        private async Task LoginToWebService()
        {
            var time         = DateTime.Today.ToShortDateString();
            var tokenRequest = new UpdateTokenRequest()
            {
                SenderId = LoginToWebServiceData.WebServiceId,
                // Token = time
                Token = "6z6d3YD4UT7faV3nZk6kp4hOG1KDsaNLTDyfRK3NZim2JR39caRiwGDbsrGcn9MTgwvHxYFprsugRpeZ7KBrtEon9wWzd0z0GCWn"
                        // Token = LoginToWebServiceData.ReadLastWebServiceToken()
            };
            var tokenResponse = await WebServiceConnection.SendPost <UpdateTokenRequest, UpdateTokenResponse>(tokenRequest, "token/update");

            LoginToWebServiceData.WebServiceToken = tokenResponse.Token;
            if (tokenResponse != null)
            {
                if (tokenResponse.Status == 0)
                {
                    Logs.WriteErrorLog("Zalogowano do WS z " + tokenResponse.Token);
                    LoginToWebServiceData.WriteLastTokenToFile(tokenResponse.Token);
                }
                Logs.WriteErrorLog(tokenResponse.Status.ToString());
            }
        }
コード例 #11
0
ファイル: OAuthTests.cs プロジェクト: Dynalon/Rainy
        public void UpdateTokenDeviceName()
        {
            string new_device_name = "My home computer";

            var token = testServer.GetAccessToken ().Token.ToShortToken ();
            var client = testServer.GetJsonClient ();
            var url = new UpdateTokenRequest ().ToUrl ("PUT");
            var req = new AccessTokenDto {
                TokenPart = token,
                DeviceName = new_device_name };
            var service_url = testServer.ListenUrl + url;
            client.Put<AccessTokenDto> (service_url, req);

            // check that the token has been updated
            var get_url = new GetTokenRequest () { Username = RainyTestServer.TEST_USER }.ToUrl ("GET");
            var get_service_url = testServer.ListenUrl + get_url;
            List<AccessTokenDto> tokens = client.Get<List<AccessTokenDto>> (get_service_url);
            var updated_token = tokens.First (t => token == t.TokenPart);

            Assert.AreEqual (new_device_name, updated_token.DeviceName);
        }
コード例 #12
0
 /// <summary>
 /// Metoda logowania do WebServisu wywoływana na starcie 
 /// </summary>
 private async Task LoginToWebService()
 {
     var time = DateTime.Today.ToShortDateString();
     var tokenRequest = new UpdateTokenRequest()
     {
         SenderId = LoginToWebServiceData.WebServiceId,
        // Token = time
         Token = "6z6d3YD4UT7faV3nZk6kp4hOG1KDsaNLTDyfRK3NZim2JR39caRiwGDbsrGcn9MTgwvHxYFprsugRpeZ7KBrtEon9wWzd0z0GCWn"
        // Token = LoginToWebServiceData.ReadLastWebServiceToken()
     };
     var tokenResponse = await WebServiceConnection.SendPost<UpdateTokenRequest, UpdateTokenResponse>(tokenRequest, "token/update");
     LoginToWebServiceData.WebServiceToken = tokenResponse.Token;
     if (tokenResponse != null)
     {
         if (tokenResponse.Status == 0)
         { 
             Logs.WriteErrorLog("Zalogowano do WS z " + tokenResponse.Token);
             LoginToWebServiceData.WriteLastTokenToFile(tokenResponse.Token);
         }
         Logs.WriteErrorLog(tokenResponse.Status.ToString());
     }
 }