Exemplo n.º 1
0
		public async Task<string> Login(BaseLoginViewModel model)
		{
			if (model != null)
			{
				_loginInfo = model;

				//Create the cookie container our client
				var cookieJar = new CookieContainer();

				//Post Password and stuff to Rest Server, Response should contain the password token cookie
				using (HttpResponseMessage response = await this._client.PostAsync(this.LoginRoute,
													new JsonContent(JsonConvert.SerializeObject(model))))
				{
					if (response.IsSuccessStatusCode)
					{
						//Grab the cookies
						var cookies = response.Headers.GetValues("Set-Cookie"); //First(x => x.StartsWith(".AspNetCore.Microsoft.Identity.Application"));

						var processedCookie = ProcessCookies(CleanCookies(cookies));

						//cache cookie
						this.AuthToken = processedCookie;

						//return ref to cookie
						return processedCookie;
					}
					else
					{
						return null;
					}
				}
			}
			else
			{
				throw new ArgumentNullException(nameof(model));
			}
		}
Exemplo n.º 2
0
		public Task<bool> SaveLoginInfoToFile(string path, BaseLoginViewModel loginInfo)
		{
			if (path != null)
			{
				BaseLoginViewModel login;

				if (_cacheLoginInfo == false && loginInfo != null)
				{
					login = loginInfo;
				}
				else
				{
					if (_loginInfo == null)
						throw new NullReferenceException(nameof(_loginInfo));

					login = _loginInfo;
				}

				return Task.Run(() =>
				{
					try
					{
						using (var textWriter = System.IO.File.CreateText(path))
						{
							_serailizer.Serialize(textWriter, login);
						}

						return true;
					}
					catch (Exception)
					{
						return false;
					}
				});
			}
			else
			{
				throw new ArgumentNullException(nameof(path));
			}
		}