Пример #1
0
		public static async Task<Imgur> CreateOAuth2AuthenticatedImgurClient()
		{
			var settings = VariousFunctions.LoadTestSettings();
			var authentication = new OAuth2Authentication(settings.ClientId, settings.ClientSecret, false);
			await OAuthHelpers.GetAccessToken(authentication, settings);
			return new Imgur(authentication);
		}
Пример #2
0
		public static async Task<OAuth2Authentication> GetAccessToken(OAuth2Authentication authentication, TestSettings settings)
		{
			authentication.AuthorizeWithToken(settings.AccessToken, settings.RefreshToken, 3600, settings.AuthorizedUsername);
			await authentication.RefreshTokens();

			settings.AccessToken = authentication.AccessToken;
			settings.RefreshToken = authentication.RefreshToken;
			VariousFunctions.SaveTestSettings(settings);

			return authentication;
		}
		public async Task TestCodeAuth()
		{
			var settings = VariousFunctions.LoadTestSettings();

			// Create a new OAuth2 Authentication
			var oAuth2Authentication = new OAuth2Authentication(settings.ClientId, settings.ClientSecret, false);
			var authorizationUrl = oAuth2Authentication.CreateAuthorizationUrl(OAuth2Type.Code, "dicks");
			var code = "1234";
			try
			{
				await oAuth2Authentication.AuthorizeWithCode(code);
			}
			catch (ImgurResponseFailedException exception)
			{
				Assert.AreEqual(exception.ImgurResponse.Data.ErrorDescription, "Refresh token doesn't exist or is invalid for the client");
			}
		}
		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");
			}
		}
Пример #5
0
 public OAuthExpiredException(OAuth2Authentication authentication, string message, Exception innerException)
     : base(message, innerException)
 {
     Authentication = authentication;
 }
Пример #6
0
 public OAuthExpiredException(OAuth2Authentication authentication, string message)
     : base(message)
 {
     Authentication = authentication;
 }
Пример #7
0
 public OAuthExpiredException(OAuth2Authentication authentication)
 {
     Authentication = authentication;
 }