コード例 #1
0
ファイル: Extensions.cs プロジェクト: jhested/tradfri-core
        public static async Task <T> RequestAsync <T>(this ICoapClient client, CoapRequest request, CancellationToken cancellationToken)
        {
            var response = await client.RequestAsync(request, cancellationToken);

            var message = Encoding.UTF8.GetString(response.Payload);

            return(JsonSerializer.Deserialize <T>(message));
        }
コード例 #2
0
        public async Task <Credentials> AuthenticateAsyncInternal(string secret, CancellationToken cancellationToken = default)
        {
            await ConnectAsync(new Credentials { Identity = "Client_identity", PresharedKey = _settings.Secret }, cancellationToken);

            var identity = RandomString(16);
            var payload  = new AuthenticationRequest {
                Identity = identity
            };
            var request = new CoapRequestBuilder()
                          .WithMethod(CoapRequestMethod.Post)
                          .WithPath(ApiEndPoint.Authentication)
                          .WithPayload(JsonSerializer.Serialize(payload))
                          .Build();

            var authResponse = await _coapClient.RequestAsync <AuthenticationResponse>(request, cancellationToken);

            return(new Credentials {
                Identity = identity, PresharedKey = authResponse.PreshardKey
            });
        }