Beispiel #1
0
        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));
        }
Beispiel #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
            });
        }