private async Task SetLastFmClients() { if (string.IsNullOrEmpty(LastFmUsername)) { return; } try { await _lastFmApiClientService.SetClients(LastFmUsername, LastFmApiSessionKey); if (!_lastFmApiClientService.UserApiClient.Authorized) { var url = _lastFmApiClientService.UserApiClient.AuthUrl; _browserService.Open(url); await _lastFmApiClientService.AuthorizeUserClient(); } LastFmApiSessionKey = _lastFmApiClientService.UserApiClient.SessionKey; } catch (LastFmApiException ex) { if (ex.ErrorCode == ErrorCode.UserNotLoggedIn) { _messenger.Send(new ShowDialogMessage(_messenger, MessageType.Error, "Last.FM Error", ex.Message)); LastFmUsername = string.Empty; LastFmApiSessionKey = null; return; } throw; } }
public async Task <ActionResult> CheckLastFmAuthorized() { #if DEBUG return(new HttpStatusCodeResult(HttpStatusCode.OK)); #endif var lastFmUsername = ConfigurationManager.AppSettings["LastFmUsername"]; var sessionKey = Request.Cookies["SK"]?.Value; if (_lastFm.UserApiClient == null) { await _lastFm.SetClients(lastFmUsername, sessionKey); } return(_lastFm.UserApiClient.Authorized ? new HttpStatusCodeResult(HttpStatusCode.OK) : (ActionResult)PartialView("_LastFmAuth", new LastFmAuthViewModel(_lastFm.UserApiClient.AuthUrl))); }