Project Windows 10 UWP.
I use library AsyncOauth .
After entering the login and password incorrectly, it is no longer possible to log in. First, the server returns the error "oauth_problem = token_rejected", then it just stops sending oauth_verifier
Error scenarios:
- When launching the application, I enter the correct username and password - everything is OK (this step can be skipped, an error occurs after the first input of incorrect data)
- After that I enter the wrong data - authorization error.
- Then again correct - oauth_problem = token_rejected
- Then again the correct ones - an authorization error (oauth_verifier stops coming in the answer)
- After restarting the application - everything is OK again before the first input of incorrect data
What could be the problem? Below is the code:
... using AsyncOAuth; ... public static async Task<AccessToken> getToken(string Login, string Password) { OAuthUtility.ComputeHash = _encryptor.GetHmacHash; try { return await GetAccessToken(Login, Password); } catch (Exception e) { throw e; } } private static async Task<AccessToken> GetAccessToken(string Login, string Password) { using (var client = new HttpClient()) { var authorizer = new OAuthAuthorizer(CONSUMER_KEY, CONSUMER_SECRET); var tokenResponse = await authorizer.GetRequestToken(BuildUri("oauth/request_token").ToString()); var requestToken = tokenResponse.Token; var pinRequestUrl = authorizer.BuildAuthorizeUrl(BuildUri("access").ToString(), requestToken) + "&mobile"; using (var query = new FormUrlEncodedContent(new Collection<KeyValuePair<string, string>>() { new KeyValuePair<string, string>("login", Login), new KeyValuePair<string, string>("password", Password) })) { using (var request = await client.PostAsync(pinRequestUrl, query)) { if (request.StatusCode != HttpStatusCode.OK) throw new UnauthorizedAccessException("Bad Auth"); var args = ParseQueryString(request.RequestMessage.RequestUri.ToString()); //Тут возникает ошибка, oauth_verifier код не приходит string verificationCode; if (args.ContainsKey("oauth_verifier")) verificationCode = Uri.UnescapeDataString(args["oauth_verifier"]); else throw new UnauthorizedAccessException("Bad Auth"); var accessTokenResponse = await authorizer.GetAccessToken(BuildUri("oauth/access_token").ToString(), requestToken, verificationCode); return accessTokenResponse.Token; } } } } private static IDictionary<string, string> ParseQueryString(string uri) { var substring = uri.Substring(((uri.LastIndexOf('?') == -1) ? 0 : uri.LastIndexOf('?') + 1)); var pairs = substring.Trim('&', 'm', 'o', 'b', 'i', 'l', 'e').Split('&'); return pairs.Select(piece => piece.Split('=')).ToDictionary(pair => pair[0], pair => pair[1]); }