Exemplo n.º 1
0
        public async Task <LoginSession> LogonAsync(JsonWebLogon logon)
        {
            using var client = GetClient(BaseUri);
            var jsonData    = JsonSerializer.Serialize(logon);
            var contentData = new StringContent(jsonData, Encoding.UTF8, MediaType);
            var response    = await client.PostAsync("Account/JsonWebLogon", contentData).ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                var resultData = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);

                var result = await JsonSerializer.DeserializeAsync <LoginSession>(resultData, DeserializerOptions).ConfigureAwait(false);

                return(result);
            }
            else
            {
                string stringData = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                string errorMessage = $"{response.ReasonPhrase}: {stringData}";

                System.Diagnostics.Debug.WriteLine("{0} ({1})", (int)response.StatusCode, errorMessage);
                throw new AdapterException((int)response.StatusCode, errorMessage);
            }
        }
Exemplo n.º 2
0
        public async Task <ILoginSession> LogonAsync(string jsonWebToken)
        {
            var result = default(ILoginSession);

            if (Adapter == AdapterType.Controller)
            {
                var accountManager = Logic.Factory.CreateAccountManager();

                result = await accountManager.LogonAsync(jsonWebToken).ConfigureAwait(false);
            }
            else if (Adapter == AdapterType.Service)
            {
                var logon = new JsonWebLogon {
                    Token = jsonWebToken
                };
                using var serviceInvoker = new Service.InvokeServiceAdapter(BaseUri);

                result = await serviceInvoker.LogonAsync(logon).ConfigureAwait(false);
            }
            return(result);
        }
 public async Task <ILoginSession> JsonWebLogonAsync([FromBody] JsonWebLogon logon)
 {
     return(ConvertTo(await AccountManager.LogonAsync(logon.Token).ConfigureAwait(false)));
 }