/// <summary> /// Authenticates and returns user info. /// </summary> /// <returns> /// The user info, including username and token. /// </returns> /// <exception cref="System.InvalidOperationException"> /// Username is empty /// or /// Password is empty /// </exception> public override async Task<UserInfo> Authenticate() { if (string.IsNullOrWhiteSpace(Username)) { throw new InvalidOperationException("Username is empty"); } if (string.IsNullOrEmpty(Password)) { throw new InvalidOperationException("Password is empty"); } var uriBuilder = new UriBuilder("https://www.douban.com/service/auth2/token"); uriBuilder.AppendAuthenticationCommonFields(ServerConnection); uriBuilder.AppendQuery(StringTable.GrantType, StringTable.Password); uriBuilder.AppendQuery(StringTable.Username, Username); uriBuilder.AppendQuery(StringTable.Password, Password); var data = uriBuilder.RemoveQuery(); var jsonContent = await ServerConnection.Post(uriBuilder.Uri, data); return ParseLogOnResult(jsonContent); }