ImgurNet.Authentication.OAuth2Authentication.AuthorizeWithPin C# (CSharp) Метод

AuthorizeWithPin() публичный Метод

Gets the token set from the pin the user has inputted. Throws a if the pin is not valid.
public AuthorizeWithPin ( string pin ) : System.Threading.Tasks.Task
pin string The pin the user entered.
Результат System.Threading.Tasks.Task
		public async Task AuthorizeWithPin(string pin)
		{
			var keyPairs = new List<KeyValuePair<string, string>>
			{
				new KeyValuePair<string, string>("client_id", ClientId),
				new KeyValuePair<string, string>("client_secret", ClientSecret),
				new KeyValuePair<string, string>("grant_type", "pin"),
				new KeyValuePair<string, string>("pin", pin)
			};
			var multi = new FormUrlEncodedContent(keyPairs.ToArray());

			var tokens = await Request.SubmitGenericRequestAsync<OAuthTokens>(Request.HttpMethod.Post, TokenEndpoint, content: multi);

			AccessToken = tokens.AccessToken;
			RefreshToken = tokens.RefreshToken;
			ExpiresAt = DateTime.UtcNow.AddSeconds(tokens.ExpiresIn);
			AuthorizedUsername = tokens.AuthorizedUsername;
		}

Usage Example

		public async Task TestPinAuth()
		{
			var settings = VariousFunctions.LoadTestSettings();

			// Create a new OAuth2 Authentication
			var oAuth2Authentication = new OAuth2Authentication(settings.ClientId, settings.ClientSecret, false);
			var authorizationUrl = oAuth2Authentication.CreateAuthorizationUrl(OAuth2Type.Pin, "dicks");
			Assert.AreNotEqual("", authorizationUrl);
			var pin = "1234";
			try
			{
				await oAuth2Authentication.AuthorizeWithPin(pin);
			}
			catch (ImgurResponseFailedException exception)
			{
				Assert.AreEqual(exception.ImgurResponse.Data.ErrorDescription, "Invalid Pin");
			}
		}