UWP Windows 10. C #

You need to log in to the server using your login and password using the OAuth protocol.

What is:

  • Consumer key
  • Consumer secret
  • Request token endpoint
  • Access token endpoint
  • Authorize URL
  • Needless to Login and Password

For WP8-8.1, there is an AsyncOAuth library, but on Windows 10 it does not work. Tell me the most simple authentication options for UWP Win 10?

PS I watched an example, wrote this code:

string SigBaseStringParams = "oauth_consumer_key=" + ConsumerKey; SigBaseStringParams += "&" + "oauth_nonce=" + nonce; SigBaseStringParams += "&" + "oauth_signature_method=HMAC-SHA1"; SigBaseStringParams += "&" + "oauth_timestamp=" + timeStamp; SigBaseStringParams += "&" + "oauth_token=" + request_token; SigBaseStringParams += "&" + "oauth_version=1.0"; string SigBaseString = "POST&"; SigBaseString = Uri.EscapeDataString(AccessTokenEndpoint) + "&" + Uri.EscapeDataString(SigBaseStringParams); string Signature = GetSignature(SigBaseString, ConsumerSecret); HttpStringContent httpContent = new HttpStringContent("oauth_verifier=" + oauth_verifier, Windows.Storage.Streams.UnicodeEncoding.Utf8); httpContent.Headers.ContentType = HttpMediaTypeHeaderValue.Parse("application/x-www-form-urlencoded"); string authorizationHeaderParams = "oauth_consumer_key=\"" + ConsumerKey + "\", oauth_nonce=\"" + nonce + "\", oauth_signature_method=\"HMAC-SHA1\"," + " oauth_signature=\"" + Uri.EscapeDataString(Signature) + "\", oauth_timestamp=\"" + timeStamp + "\", oauth_token=\"" + Uri.EscapeDataString(request_token) + "\", oauth_version=\"1.0\""; HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new HttpCredentialsHeaderValue("OAuth", authorizationHeaderParams); var httpResponseMessage = await httpClient.PostAsync(new Uri(AccessTokenEndpoint), httpContent); string response = await httpResponseMessage.Content.ReadAsStringAsync(); 

receipt code signature:

 string GetSignature(string sigBaseString, string consumerSecretKey) { IBuffer KeyMaterial = CryptographicBuffer.ConvertStringToBinary(consumerSecretKey + "&", BinaryStringEncoding.Utf8); MacAlgorithmProvider HmacSha1Provider = MacAlgorithmProvider.OpenAlgorithm("HMAC_SHA1"); CryptographicKey MacKey = HmacSha1Provider.CreateKey(KeyMaterial); IBuffer DataToBeSigned = CryptographicBuffer.ConvertStringToBinary(sigBaseString, BinaryStringEncoding.Utf8); IBuffer SignatureBuffer = CryptographicEngine.Sign(MacKey, DataToBeSigned); string Signature = CryptographicBuffer.EncodeToBase64String(SignatureBuffer); return Signature; } 

I get the requestToken and validationToken normally, but in the last request I get the string "oauth_problem = signature_invalid & debug_sbs = POST ...". What am I doing wrong?

1 answer 1

Solved the problem of porting AyncOauth to UWP Win 10 NuGet of the original