/// <summary> /// Log user in to Twitter. /// </summary> /// <returns>Boolean indicating login success.</returns> public async Task <bool> LoginAsync() { var credentials = _passwordManager.Get("TwitterAccessToken"); var user = await _storageManager.GetAsync("TwitterScreenName"); if (!string.IsNullOrEmpty(user) && credentials != null) { _tokens.AccessToken = credentials.UserName; _tokens.AccessTokenSecret = credentials.Password; UserScreenName = user; LoggedIn = true; return(true); } if (await InitializeRequestAccessTokensAsync(_tokens.CallbackUri) == false) { LoggedIn = false; return(false); } string requestToken = _tokens.RequestToken; string twitterUrl = $"{OAuthBaseUrl}/authorize?oauth_token={requestToken}"; Uri startUri = new Uri(twitterUrl); Uri endUri = new Uri(_tokens.CallbackUri); var result = await _authenticationBroker.Authenticate(startUri, endUri); switch (result.ResponseStatus) { case AuthenticationResultStatus.Success: LoggedIn = true; return(await ExchangeRequestTokenForAccessTokenAsync(result.ResponseData)); case AuthenticationResultStatus.ErrorHttp: Debug.WriteLine("WAB failed, message={0}", result.ResponseErrorDetail.ToString()); LoggedIn = false; return(false); case AuthenticationResultStatus.UserCancel: Debug.WriteLine("WAB user aborted."); LoggedIn = false; return(false); } LoggedIn = false; return(false); }
/// <summary> /// Log user in to Weibo. /// </summary> /// <returns>Boolean indicating login success.</returns> public async Task <bool> LoginAsync() { var credentials = _passwordManager.Get(PasswordKey); string uidString = await _storageManager.GetAsync(StorageKey); if (long.TryParse(uidString, out var uid) && credentials != null) { _tokens.AccessToken = credentials.Password; Uid = uid; LoggedIn = true; return(true); } string appKey = _tokens.AppKey; string redirectUri = _tokens.RedirectUri; string weiboUrl = $"{OAuthBaseUrl}/authorize?client_id={appKey}&redirect_uri={redirectUri}"; Uri startUri = new Uri(weiboUrl); Uri endUri = new Uri(redirectUri); var result = await _authenticationBroker.Authenticate(startUri, endUri); switch (result.ResponseStatus) { case AuthenticationResultStatus.Success: LoggedIn = true; return(await ExchangeRequestTokenForAccessTokenAsync(result.ResponseData)); case AuthenticationResultStatus.ErrorHttp: LoggedIn = false; return(false); case AuthenticationResultStatus.UserCancel: LoggedIn = false; return(false); } LoggedIn = false; return(false); }
/// <summary> /// Log user in to LinkedIn. /// </summary> /// <returns>Boolean indicating login success.</returns> public async Task <bool> LoginAsync() { var user = await _storageManager.GetAsync(LinkedInConstants.STORAGEKEYUSER); var credential = _passwordManager.Get(LinkedInConstants.STORAGEKEYACCESSTOKEN); if (!string.IsNullOrEmpty(user) && credential != null) { Tokens.AccessToken = credential.Password; Username = user; LoggedIn = true; return(true); } string authorizeCode = await GetAuthorizeCodeAsync(Tokens, RequiredPermissions); if (!string.IsNullOrEmpty(authorizeCode)) { var accessToken = await GetAccessTokenAsync(Tokens, authorizeCode); if (!string.IsNullOrEmpty(accessToken)) { Tokens.AccessToken = accessToken; _passwordManager.Store(LinkedInConstants.STORAGEKEYACCESSTOKEN, new PasswordCredential { UserName = LinkedInConstants.STORAGEKEYUSER, Password = accessToken }); await _storageManager.SetAsync(LinkedInConstants.STORAGEKEYUSER, LinkedInConstants.STORAGEKEYUSER); return(true); } } LoggedIn = false; return(false); }