Exemplo n.º 1
0
        public async Task <IActionResult> Refresh([FromBody] RequestTokenRefresh token)
        {
            var principal = GetPrincipalFromExpiredToken(token.Token);
            var userid    = Convert.ToInt64(principal.Claims.First(c => c.Type == "UserId").Value);

            var savedRefreshToken = await accountService.GetRefreshToken(userid);

            //if (savedRefreshToken != token.RefreshToken)
            //    throw new SecurityTokenException("Invalid refresh token");

            var creationDate    = DateTime.Now;
            var expirationDate  = creationDate.AddMinutes(tokenConfigurations.Minutes);
            var newJwtToken     = GenerateToken(principal.Claims, expirationDate);
            var newRefreshToken = GenerateRefreshToken();
            await accountService.SaveRefreshToken(userid, newRefreshToken, creationDate);

            return(new ObjectResult(new TokenData
            {
                Authenticated = true,
                Created = creationDate,
                Expiration = expirationDate,
                AccessToken = newJwtToken,
                RefreshToken = newRefreshToken,
                Message = "OK"
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Receive a new Access token
        /// </summary>
        /// <exception cref="LeapPlay.Api.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="requestTokenRefresh">Refresh Token Dto (optional)</param>
        /// <param name="authorization">Any previous Access Token. (optional)</param>
        /// <returns>Task of ApiResponse (AccessToken)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <AccessToken> > RefreshTokenAsyncWithHttpInfo(RequestTokenRefresh requestTokenRefresh = null, string authorization = null)
        {
            var    localVarPath         = "./api/v1/auth/refreshtoken";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(this.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-patch+json",
                "application/json",
                "text/json",
                "application/_*+json"
            };
            String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (authorization != null)
            {
                localVarHeaderParams.Add("Authorization", this.Configuration.ApiClient.ParameterToString(authorization));                        // header parameter
            }
            if (requestTokenRefresh != null && requestTokenRefresh.GetType() != typeof(byte[]))
            {
                localVarPostBody = this.Configuration.ApiClient.Serialize(requestTokenRefresh); // http body (model) parameter
            }
            else
            {
                localVarPostBody = requestTokenRefresh; // byte array
            }


            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                            Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("RefreshToken", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <AccessToken>(localVarStatusCode,
                                                 localVarResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString()),
                                                 (AccessToken)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(AccessToken))));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Receive a new Access token
        /// </summary>
        /// <exception cref="LeapPlay.Api.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="requestTokenRefresh">Refresh Token Dto (optional)</param>
        /// <param name="authorization">Any previous Access Token. (optional)</param>
        /// <returns>Task of AccessToken</returns>
        public async System.Threading.Tasks.Task <AccessToken> RefreshTokenAsync(RequestTokenRefresh requestTokenRefresh = null, string authorization = null)
        {
            ApiResponse <AccessToken> localVarResponse = await RefreshTokenAsyncWithHttpInfo(requestTokenRefresh, authorization);

            return(localVarResponse.Data);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Receive a new Access token
        /// </summary>
        /// <exception cref="LeapPlay.Api.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="requestTokenRefresh">Refresh Token Dto (optional)</param>
        /// <param name="authorization">Any previous Access Token. (optional)</param>
        /// <returns>AccessToken</returns>
        public AccessToken RefreshToken(RequestTokenRefresh requestTokenRefresh = null, string authorization = null)
        {
            ApiResponse <AccessToken> localVarResponse = RefreshTokenWithHttpInfo(requestTokenRefresh, authorization);

            return(localVarResponse.Data);
        }