public IActionResult RenewBearerToken(RenewTokenRequest req) { try { return(Ok(_dbService.RenewToken(req))); } catch (TokenException e) { return(NotFound(e)); } }
public RenewTokenResponse RenewToken(RenewTokenRequest req) { var client = _context.Clients.Where (p => p.RefreshToken.Equals(req.RefreshToken)) .FirstOrDefault(); if (client == null) { throw new TokenException("Refresh token incorrect"); } var refreshToken = Guid.NewGuid(); client.RefreshToken = refreshToken.ToString(); _context.Update(client); var claims = new[] { new Claim(ClaimTypes.NameIdentifier, client.Login), new Claim(ClaimTypes.Name, client.FirstName + " " + client.LastName), new Claim(ClaimTypes.Role, "client") }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["SecretKey"])); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken ( issuer: "s19434", audience: "Clients", claims: claims, expires: DateTime.Now.AddMinutes(15), signingCredentials: creds ); _context.SaveChanges(); return(new RenewTokenResponse { AccessToken = new JwtSecurityTokenHandler().WriteToken(token), RefreshToken = refreshToken.ToString() }); }
/// <summary> /// The user renews access token and refresh token /// </summary> /// <exception cref="ManualTransmissionClient.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="renewTokenRequest"></param> /// <returns>Task of ApiResponse (AccessTokenResponse)</returns> public async System.Threading.Tasks.Task <ApiResponse <AccessTokenResponse> > RenewTokenAsyncWithHttpInfo(RenewTokenRequest renewTokenRequest) { // verify the required parameter 'renewTokenRequest' is set if (renewTokenRequest == null) { throw new ApiException(400, "Missing required parameter 'renewTokenRequest' when calling UserApi->RenewToken"); } var localVarPath = "/login/refreshToken"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new Dictionary <String, String>(); var localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader); var localVarFormParams = new Dictionary <String, String>(); var localVarFileParams = new Dictionary <String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json" }; String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json" }; String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } if (renewTokenRequest != null && renewTokenRequest.GetType() != typeof(byte[])) { localVarPostBody = Configuration.ApiClient.Serialize(renewTokenRequest); // http body (model) parameter } else { localVarPostBody = renewTokenRequest; // byte array } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (ExceptionFactory != null) { Exception exception = ExceptionFactory("RenewToken", localVarResponse); if (exception != null) { throw exception; } } return(new ApiResponse <AccessTokenResponse>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (AccessTokenResponse)Configuration.ApiClient.Deserialize(localVarResponse, typeof(AccessTokenResponse)))); }
/// <summary> /// The user renews access token and refresh token /// </summary> /// <exception cref="ManualTransmissionClient.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="renewTokenRequest"></param> /// <returns>Task of AccessTokenResponse</returns> public async System.Threading.Tasks.Task <AccessTokenResponse> RenewTokenAsync(RenewTokenRequest renewTokenRequest) { ApiResponse <AccessTokenResponse> localVarResponse = await RenewTokenAsyncWithHttpInfo(renewTokenRequest); return(localVarResponse.Data); }
/// <summary> /// The user renews access token and refresh token /// </summary> /// <exception cref="ManualTransmissionClient.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="renewTokenRequest"></param> /// <returns>AccessTokenResponse</returns> public AccessTokenResponse RenewToken(RenewTokenRequest renewTokenRequest) { ApiResponse <AccessTokenResponse> localVarResponse = RenewTokenWithHttpInfo(renewTokenRequest); return(localVarResponse.Data); }
/// <summary> /// The user renews access token and refresh token /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='renewTokenRequest'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async System.Threading.Tasks.Task <AccessTokenResponse> RenewTokenAsync(this ILoanPredictService1484942117 operations, RenewTokenRequest renewTokenRequest, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { using (var _result = await operations.RenewTokenWithHttpMessagesAsync(renewTokenRequest, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// The user renews access token and refresh token /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='renewTokenRequest'> /// </param> public static AccessTokenResponse RenewToken(this ILoanPredictService1484942117 operations, RenewTokenRequest renewTokenRequest) { return(System.Threading.Tasks.Task.Factory.StartNew(s => ((ILoanPredictService1484942117)s).RenewTokenAsync(renewTokenRequest), operations, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// RenewToken /// </summary> /// <remarks> /// OAuth access tokens besides your application's personal access token expire after 30 days. Use this endpoint to renew an expired token. If you provide a token that isn't expired, this endpoint does not extend its lifetime. /// You cannot renew an access token that has been expired for more than 15 days.Instead, the associated merchant must complete the OAuth flow from the beginning. /// </remarks> /// <exception cref="T:SquareConnectApiClient.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="authorization">Important: The Authorization header you provide to this endpoint must have the following format: Authorization: Client APPLICATION_SECRET. Replace APPLICATION_SECRET with your application's secret, available from the application dashboard.</param> /// <param name="clientId">Your application's ID, available from the application dashboard.</param> /// <param name="body">>An object containing the fields to POST for the request.\n\nSee the corresponding object definition for field details.</param> /// <returns>Task of ApiResponse (RenewTokenResponse)</returns> public async Task <ApiResponse <RenewTokenResponse> > RenewTokenAsyncWithHttpInfo(string authorization, string clientId, RenewTokenRequest body) { // verify the required parameter 'authorization' is set if (authorization == null) { throw new ApiException(400, "Missing required parameter 'authorization' when calling RenewToken"); } // verify the required parameter 'clientId' is set if (clientId == null) { throw new ApiException(400, "Missing required parameter 'clientId' when calling RenewToken"); } // verify the required parameter 'body' is set if (body == null) { throw new ApiException(400, "Missing required parameter 'body' when calling RenewToken"); } var localVarPath = "/oauth2/clients/{client_id}/access-token/renew"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new Dictionary <String, String>(); var localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader); var localVarFormParams = new Dictionary <String, String>(); var localVarFileParams = new Dictionary <String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json" }; String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json" }; String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } // set "format" to json by default // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json localVarPathParams.Add("format", "json"); if (clientId != null) { localVarPathParams.Add("client_id", Configuration.ApiClient.ParameterToString(clientId)); // path parameter } if (authorization != null) { localVarHeaderParams.Add("Authorization", Configuration.ApiClient.ParameterToString(authorization)); // header parameter } if (body.GetType() != typeof(byte[])) { localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter } else { localVarPostBody = body; // byte array } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (localVarStatusCode >= 400) { throw new ApiException(localVarStatusCode, "Error calling Renew Token: " + localVarResponse.Content, localVarResponse.Content); } else if (localVarStatusCode == 0) { throw new ApiException(localVarStatusCode, "Error calling Renew Token: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); } return(new ApiResponse <RenewTokenResponse>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (RenewTokenResponse)Configuration.ApiClient.Deserialize(localVarResponse, typeof(RenewTokenResponse)))); }
/// <summary> /// RenewToken /// </summary> /// <remarks> /// OAuth access tokens besides your application's personal access token expire after 30 days. Use this endpoint to renew an expired token. If you provide a token that isn't expired, this endpoint does not extend its lifetime. /// You cannot renew an access token that has been expired for more than 15 days.Instead, the associated merchant must complete the OAuth flow from the beginning. /// </remarks> /// <exception cref="T:SquareConnectApiClient.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="authorization">Important: The Authorization header you provide to this endpoint must have the following format: Authorization: Client APPLICATION_SECRET. Replace APPLICATION_SECRET with your application's secret, available from the application dashboard.</param> /// <param name="clientId">Your application's ID, available from the application dashboard.</param> /// <param name="body">>An object containing the fields to POST for the request.\n\nSee the corresponding object definition for field details.</param> /// <returns>Task of ARenewTokenResponse</returns> public async Task <RenewTokenResponse> RenewTokenAsync(string authorization, string clientId, RenewTokenRequest body) { ApiResponse <RenewTokenResponse> localVarResponse = await RenewTokenAsyncWithHttpInfo(authorization, clientId, body); return(localVarResponse.Data); }
/// <summary> /// RenewToken /// </summary> /// <remarks> /// OAuth access tokens besides your application's personal access token expire after 30 days. Use this endpoint to renew an expired token. If you provide a token that isn't expired, this endpoint does not extend its lifetime. /// You cannot renew an access token that has been expired for more than 15 days.Instead, the associated merchant must complete the OAuth flow from the beginning. /// </remarks> /// <exception cref="T:SquareConnectApiClient.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="authorization">Important: The Authorization header you provide to this endpoint must have the following format: Authorization: Client APPLICATION_SECRET. Replace APPLICATION_SECRET with your application's secret, available from the application dashboard.</param> /// <param name="clientId">Your application's ID, available from the application dashboard.</param> /// <param name="body">>An object containing the fields to POST for the request.\n\nSee the corresponding object definition for field details.</param> /// <returns>RenewTokenResponse</returns> public RenewTokenResponse RenewToken(string authorization, string clientId, RenewTokenRequest body) { ApiResponse <RenewTokenResponse> localVarResponse = RenewTokenWithHttpInfo(authorization, clientId, body); return(localVarResponse.Data); }
/// <summary> /// The user renews access token and refresh token /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='renewTokenRequest'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async System.Threading.Tasks.Task <AccessTokenResponse> RenewTokenAsync(this ICheckLocationViabilityForHotel operations, RenewTokenRequest renewTokenRequest, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { using (var _result = await operations.RenewTokenWithHttpMessagesAsync(renewTokenRequest, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// The user renews access token and refresh token /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='renewTokenRequest'> /// </param> public static AccessTokenResponse RenewToken(this ICheckLocationViabilityForHotel operations, RenewTokenRequest renewTokenRequest) { return(System.Threading.Tasks.Task.Factory.StartNew(s => ((ICheckLocationViabilityForHotel)s).RenewTokenAsync(renewTokenRequest), operations, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// The user renews access token and refresh token /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='renewTokenRequest'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <AccessTokenResponse> RenewTokenAsync(this ICarsService operations, RenewTokenRequest renewTokenRequest, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.RenewTokenWithHttpMessagesAsync(renewTokenRequest, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// The user renews access token and refresh token /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='renewTokenRequest'> /// </param> public static AccessTokenResponse RenewToken(this ICarsService operations, RenewTokenRequest renewTokenRequest) { return(Task.Factory.StartNew(s => ((ICarsService)s).RenewTokenAsync(renewTokenRequest), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }