コード例 #1
0
        public async Task Logout(CancellationToken cancellationToken)
        {
            if (!IsLoggedIn())
            {
                return;
            }


            //was var logoutCommand = NitroCommand.Create<NitroLogoutCommand>(this, new NitroLogoutData);
            var logoutCommand = NitroCommandFactory.Create <NitroLogoutCommand>(this);
            var response      = await logoutCommand.ExecuteAsync(cancellationToken).ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                throw new HttpRequestException("Could not log off.\n" + response);
            }
        }
コード例 #2
0
        public async Task Login(CancellationToken cancellationToken)
        {
            var loginCommand = NitroCommandFactory.Create <NitroLoginCommand>(this, _credentials);
            var response     = await loginCommand.ExecuteAsync(cancellationToken).ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                throw new HttpRequestException("Could not log on.\n" + response);
            }

            await using var contentStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);

            var content =
                await JsonSerializer.DeserializeAsync <NitroLoginResponse>(
                    contentStream,
                    NitroServiceSerializerOptions.JsonSerializerOptions
                    ).ConfigureAwait(false);

            ConfigureAuthenticationCookieHeader(content.SessionId);
        }