Пример #1
0
 private static void HandleRefreshCallback <TRequest, TResponse>(IWebCall <TRequest, TResponse> webCall, bool needAuthToken, string authToken, bool needSession, IWebCallEncryptor webCallEncryptor) where TRequest : BaseUserRequest where TResponse : BaseResponse, new()
 {
     if (needAuthToken && authToken != null)
     {
         webCall.SetHeader("X-Mix-OneIdToken", authToken);
     }
     if (needSession && webCallEncryptor != null)
     {
         webCall.WebCallEncryptor = webCallEncryptor;
         webCall.SetHeader("X-Mix-UserSessionId", webCallEncryptor.SessionId);
     }
     if (webCall.RefreshStatus == WebCallRefreshStatus.WaitingForRefreshCallback)
     {
         webCall.RefreshStatus = WebCallRefreshStatus.NotRefreshing;
         bool flag = true;
         if (needAuthToken && authToken == null)
         {
             flag = false;
             webCall.DispatchError("GuestController token expired and couldn't get a new token");
         }
         if (needSession && webCallEncryptor == null)
         {
             flag = false;
             webCall.DispatchError("Session expired and couldn't start a new session");
         }
         if (flag)
         {
             webCall.Execute();
         }
     }
     else
     {
         webCall.RefreshStatus = WebCallRefreshStatus.RefreshedWhileWaitingForCallback;
     }
 }
Пример #2
0
        private void HandleOnUnauthorized <TRequest, TResponse>(IWebCall <TRequest, TResponse> webCall, WebCallUnauthorizedEventArgs e) where TRequest : BaseUserRequest where TResponse : BaseResponse, new()
        {
            if (webCallEncryptor.SessionId == null)
            {
                webCall.DispatchError("Unauthorized access to start a new session!");
            }
            else if (!isSessionRefreshing)
            {
                if (webCall.RefreshStatus == WebCallRefreshStatus.RefreshedWhileWaitingForCallback)
                {
                    webCall.RefreshStatus = WebCallRefreshStatus.NotRefreshing;
                    webCall.Execute();
                    return;
                }
                webCall.RefreshStatus = WebCallRefreshStatus.WaitingForRefreshCallback;
                isSessionRefreshing   = true;
                switch (e.Status)
                {
                case "UNAUTHORIZED_ONEID_TOKEN":
                    sessionRefresher.RefreshGuestControllerToken(swid, delegate
                    {
                        isSessionRefreshing = false;
                    }, delegate
                    {
                        isSessionRefreshing = false;
                    });
                    break;

                case "UNAUTHORIZED_MIX_SESSION":
                    sessionRefresher.RefreshSession(guestControllerAccessToken, swid, delegate(IWebCallEncryptor encryptor)
                    {
                        isSessionRefreshing = false;
                        webCallEncryptor    = encryptor;
                    }, delegate
                    {
                        isSessionRefreshing = false;
                        this.OnAuthenticationLost(this, new AuthenticationUnavailableEventArgs());
                    });
                    break;

                case "UNAUTHORIZED_BANNED":
                    webCall.DispatchError("Account is banned!");
                    isSessionRefreshing = false;
                    this.OnAuthenticationLost(this, new AccountBannedEventArgs(logger, e.ResponseText));
                    break;

                default:
                    sessionRefresher.RefreshAll(swid, delegate(IWebCallEncryptor encryptor)
                    {
                        isSessionRefreshing = false;
                        webCallEncryptor    = encryptor;
                    }, delegate
                    {
                        isSessionRefreshing = false;
                        this.OnAuthenticationLost(this, new AuthenticationUnavailableEventArgs());
                    });
                    break;
                }
            }
            else
            {
                webCall.RefreshStatus = WebCallRefreshStatus.WaitingForRefreshCallback;
            }
        }