예제 #1
0
        /// <summary>
        /// Register a new ID `JWT(sub, devtoken)`
        ///
        /// v5: `JWT(sub, pk, devtoken, ...)`
        ///
        /// See: https://github.com/skion/authentiq/wiki/JWT-Examples
        ///
        /// Key_register key
        /// </summary>
        /// <param name="requestBody">Authentiq ID to register</param>
        public async Task Key_registerAsync(AuthentiqID requestBody, Action <System.Net.Http.Headers.HttpRequestHeaders> handleHeaders = null)
        {
            var requestUri = "key";

            using (var request = new HttpRequestMessage(HttpMethod.Post, requestUri))
            {
                using (var requestWriter = new System.IO.StringWriter())
                {
                    var requestSerializer = JsonSerializer.Create(jsonSerializerSettings);
                    requestSerializer.Serialize(requestWriter, requestBody);
                    var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json");
                    request.Content = content;
                    if (handleHeaders != null)
                    {
                        handleHeaders(request.Headers);
                    }

                    var responseMessage = await client.SendAsync(request);

                    try
                    {
                        responseMessage.EnsureSuccessStatusCodeEx();
                    }
                    finally
                    {
                        responseMessage.Dispose();
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Update Authentiq ID by replacing the object.
        ///
        /// v4: `JWT(sub,email,phone)` to bind email/phone hash;
        ///
        /// v5: POST issuer-signed email & phone scopes
        /// and PUT to update registration `JWT(sub, pk, devtoken, ...)`
        ///
        /// See: https://github.com/skion/authentiq/wiki/JWT-Examples
        ///
        /// Key_bind key/{PK}
        /// </summary>
        /// <param name="PK">Public Signing Key - Authentiq ID (43 chars)</param>
        /// <param name="requestBody">Authentiq ID to register</param>
        /// <returns>Successfully updated</returns>
        public async Task <string> Key_bindAsync(string PK, AuthentiqID requestBody, Action <System.Net.Http.Headers.HttpRequestHeaders> handleHeaders = null)
        {
            var requestUri = "key/" + (PK == null? "" : Uri.EscapeDataString(PK));

            using (var request = new HttpRequestMessage(HttpMethod.Put, requestUri))
            {
                using (var requestWriter = new System.IO.StringWriter())
                {
                    var requestSerializer = JsonSerializer.Create(jsonSerializerSettings);
                    requestSerializer.Serialize(requestWriter, requestBody);
                    var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json");
                    request.Content = content;
                    if (handleHeaders != null)
                    {
                        handleHeaders(request.Headers);
                    }

                    var responseMessage = await client.SendAsync(request);

                    try
                    {
                        responseMessage.EnsureSuccessStatusCodeEx();
                        var stream = await responseMessage.Content.ReadAsStreamAsync();

                        using (JsonReader jsonReader = new JsonTextReader(new System.IO.StreamReader(stream)))
                        {
                            return(jsonReader.ReadAsString());
                        }
                    }
                    finally
                    {
                        responseMessage.Dispose();
                    }
                }
            }
        }