public void SetCurrentStatusByToken(string token) { if (!string.IsNullOrEmpty(token)) { int index = token.IndexOf('|'); if (index >= 0) { // Token found, save the info ActiveUserToken = token.Substring(index + 1); ActiveUserLenovoIdEmailAddress = token.Substring(0, index); if (ActiveUserLenovoIdEmailAddress.EndsWith("@lenovoid.com") && ActiveUserToken.Equals(LenovoIdConstants.StarterToken)) { CurrentStatus = LenovoIdStatus.StarterId; } else { CurrentStatus = LenovoIdStatus.SignedIn; } } else { // No token, user is signing out CurrentStatus = LenovoIdStatus.SignedOut; } } }
private async Task <bool> ParseTokenResultAsync(WebTokenRequestResult result, bool allowDownloadSiteToPopUp) { bool success = false; if (result != null) { if (result.ResponseStatus == WebTokenRequestStatus.Success) { if (result.ResponseData != null && result.ResponseData.Count > 0 && result.ResponseData[0].Token != null) { string value = result.ResponseData[0].Token; int index = value.IndexOf('|'); // Format is userID|token if (index >= 0) { // Token found, save the info ActiveUserToken = value.Substring(index + 1); ActiveUserLenovoIdEmailAddress = value.Substring(0, index); if (ActiveUserLenovoIdEmailAddress.EndsWith("@lenovoid.com") && ActiveUserToken.Equals(LenovoIdConstants.StarterToken)) { CurrentStatus = LenovoIdStatus.StarterId; } else { CurrentStatus = LenovoIdStatus.SignedIn; } } else { // No token, user is signing out CurrentStatus = LenovoIdStatus.SignedOut; } success = true; } else { //Logger.Log(LogSeverity.Error, "LenovoIdAgent: Couldn't parse response because response data wasn't complete"); } } else if (result.ResponseStatus == WebTokenRequestStatus.UserCancel) { // User cancelled out of the Lenovo ID sign in interface //Logger.Log(LogSeverity.Error, "LenovoIdAgent: User cancelled login prompt"); } else if (result.ResponseStatus == WebTokenRequestStatus.UserInteractionRequired) { /*Start -- Temporary code to accomodate the new LID app as it is not backward compatible*/ if (firstTimeUserInteractionRequired) { firstTimeUserInteractionRequired = false; var provider = await GetLenovoIdAccountProvider(); var status = await GetTokenSilentlyAsync(provider, LenovoIdConstants.PROVIDER_SCOPE_SILENTLY_V2, LENOVO_CLIENT_ID); if (status) { firstTimeUserInteractionRequired = true; return(status); } } /*End -- Temporary code*/ // User interaction is required to complete the request. This option is only applicable to requests made with GetTokenSilentlyAsync. // If this status is returned, repeat the request with RequestTokenAsync. CurrentStatus = LenovoIdStatus.SignedOut; //Logger.Log(LogSeverity.Information, "ResponseStatus is UserInteractionRequired"); } else { // Status is AccountProviderNotAvailable, ProviderError, or AccountSwitch CurrentStatus = LenovoIdStatus.SignedOut; ActiveUserLenovoIdEmailAddress = string.Empty; string errorMessage = string.Empty; if (result.ResponseError != null && !String.IsNullOrWhiteSpace(result.ResponseError.ErrorMessage)) { errorMessage = " - Error message: " + result.ResponseError.ErrorCode + " " + result.ResponseError.ErrorMessage; } // Launch the download site if appropriate if (allowDownloadSiteToPopUp) { //Logger.Log(LogSeverity.Error, "LenovoIdAgent: ResponseStatus was " + result.ResponseStatus + " and the download site will launch" + errorMessage); } else { //Logger.Log(LogSeverity.Error, "LenovoIdAgent: ResponseStatus was " + result.ResponseStatus + " and the download site was NOT launched" + errorMessage); } } } else { //Logger.Log(LogSeverity.Error, "LenovoIdAgent: WebTokenRequestResult was null, can't parse it"); } return(success); }