Exemple #1
0
 public async Task AuthorizationRequest()
 {
     var client           = new ImgurClient(_clientId);
     var endpoint         = new OAuth2Endpoint(client);
     var authorizationUrl = endpoint.GetAuthorizationUrl(OAuth2ResponseType.Pin);
     await Windows.System.Launcher.LaunchUriAsync(new Uri(authorizationUrl));
 }
        private static async Task InitiateClient(bool getPin = true)
        {
            if (disable)
            {
                return;
            }
            var data = File.OpenText(Program.DataPath("imgflip pins", "txt")).ReadToEnd().Split('|');

            client = new ImgurClient($"{data[0]}", $"{data[1]}");
            end    = new OAuth2Endpoint(client);
            string g = end.GetAuthorizationUrl(Imgur.API.Enums.OAuth2ResponseType.Token);

            //System.Net.WebClient wc = new System.Net.WebClient();
            //byte[] raw = wc.DownloadData(g);

            //string webData = System.Text.Encoding.UTF8.GetString(raw);
            //Console.WriteLine(g);
            //ExtensionMethods.WriteToLog(ExtensionMethods.LogType.CustomMessage, null, g + "\n\n\n" + webData);
            if (getPin)
            {
                token = await end.GetTokenByPinAsync($"{data[2]}");

                client.SetOAuth2Token(token);
            }
            endpoint = new ImageEndpoint(client);
            disable  = true;
        }
Exemple #3
0
        public void AskToken()
        {
            var endpoint         = new OAuth2Endpoint(Imgur);
            var authorizationUrl = endpoint.GetAuthorizationUrl(OAuth2ResponseType.Pin);

            System.Diagnostics.Process.Start(authorizationUrl);
        }
Exemple #4
0
        public static async Task <IOAuth2Token> GetToken()
        {
            OAuth2Endpoint auth  = new OAuth2Endpoint(new ImgurClient(Properties.Settings.Default.ClientId, Properties.Settings.Default.ClientSecret));
            IOAuth2Token   token = null;

            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.Token))
            {
                token = JsonConvert.DeserializeObject <OAuth2Token>(Properties.Settings.Default.Token);
                if (token != null)
                {
                    if (token.ExpiresIn > 0)
                    {
                        return(token);
                    }
                    token = await auth.GetTokenByRefreshTokenAsync(token.RefreshToken);

                    Properties.Settings.Default.Token = JsonConvert.SerializeObject(token);
                    Properties.Settings.Default.Save();
                }
            }
            Process.Start(auth.GetAuthorizationUrl(Imgur.API.Enums.OAuth2ResponseType.Pin));
            string pin = await DialogCoordinator.Instance.ShowInputAsync(Context, "Enter Imgur Pin", "");

            token = await auth.GetTokenByPinAsync(pin);

            Properties.Settings.Default.Token = JsonConvert.SerializeObject(token);
            Properties.Settings.Default.Save();
            return(token);
        }
Exemple #5
0
        public void Authorize()
        {
            string redirectUrl = _endpoint.GetAuthorizationUrl(Imgur.API.Enums.OAuth2ResponseType.Pin);

            Process.Start(redirectUrl);

            success.Show("Please enter the PIN you received on the Website!", TimeSpan.FromSeconds(2));
        }
Exemple #6
0
        public IActionResult LoginImgUr()
        {
            var client           = new ImgurClient(this.imgUrUploadSettings.ClientID, this.imgUrUploadSettings.ClientSecret);
            var endpoint         = new OAuth2Endpoint(client);
            var authorizationUrl = endpoint.GetAuthorizationUrl(OAuth2ResponseType.Token);

            return(Ok(new { data = authorizationUrl }));
        }
        public static string GetAuthorizationUrl()
        {
            var client           = new ImgurClient(ClientIdImgur);
            var endpoint         = new OAuth2Endpoint(client);
            var authorizationUrl = endpoint.GetAuthorizationUrl(OAuth2ResponseType.Token);

            return(authorizationUrl);
        }
        public void GetAuthorizationUrl_SetStateNull_Equal()
        {
            var apiClient = new ApiClient("xyz", "deb");
            var endpoint  = new OAuth2Endpoint(apiClient, new HttpClient());
            var expected  = "https://api.imgur.com/oauth2/authorize?client_id=xyz&response_type=token&state=";

            Assert.Equal(expected, endpoint.GetAuthorizationUrl());
        }
        public void GetAuthorizationUrl_SetState_Equal()
        {
            var apiClient = new ApiClient("abc", "ioa");
            var endpoint  = new OAuth2Endpoint(apiClient, new HttpClient());
            var expected  = "https://api.imgur.com/oauth2/authorize?client_id=abc&response_type=token&state=test";

            Assert.Equal(expected, endpoint.GetAuthorizationUrl("test"));
        }
Exemple #10
0
        public void Authorize()
        {
            string redirectUrl = _endpoint.GetAuthorizationUrl(OAuth2ResponseType.Pin);

            Process.Start(redirectUrl);

            _success.Show(strings.plsPin, TimeSpan.FromSeconds(2));
        }
        public IActionResult LoginImgurProfile()
        {
            var client           = new ImgurClient(ClientIdImgur);
            var endpoint         = new OAuth2Endpoint(client);
            var authorizationUrl = endpoint.GetAuthorizationUrl(OAuth2ResponseType.Token);

            return(this.Redirect(authorizationUrl));
        }
        public void GetAuthorizationUrl_SetStateNull_AreEqual()
        {
            var client   = new ImgurClient("xyz", "deb");
            var endpoint = new OAuth2Endpoint(client);
            var expected = "https://api.imgur.com/oauth2/authorize?client_id=xyz&response_type=Code&state=";

            Assert.AreEqual(expected, endpoint.GetAuthorizationUrl(OAuth2ResponseType.Code, null));
        }
        public void GetAuthorizationUrl_SetState_AreEqual()
        {
            var client   = new ImgurClient("abc", "ioa");
            var endpoint = new OAuth2Endpoint(client);
            var expected = "https://api.imgur.com/oauth2/authorize?client_id=abc&response_type=Code&state=test";

            Assert.AreEqual(expected, endpoint.GetAuthorizationUrl(OAuth2ResponseType.Code, "test"));
        }
Exemple #14
0
        public static async Task ConnectImgurApi()
        {
            var client = new ImgurClient("3f8dfa6f3541120");

            var endpoint         = new OAuth2Endpoint(client);
            var authorizationUrl = endpoint.GetAuthorizationUrl(OAuth2ResponseType.Pin);

            await Windows.System.Launcher.LaunchUriAsync(new Uri(authorizationUrl));
        }
Exemple #15
0
        public static string GetAuthorizationUrl()
        {
            ApiSettings settings = GetApiLogin();

            Client = new ImgurClient(settings.ClientId, settings.ClientSecret);
            var endpoint = new OAuth2Endpoint(Client);

            return(endpoint.GetAuthorizationUrl(Imgur.API.Enums.OAuth2ResponseType.Token));
        }
Exemple #16
0
        public string AuthUser()
        {
            IniData authData = null;
            string  clientId = null;
            // Create a parser to read the auth.ini file
            var parser = new FileIniDataParser();

            try {
                authData = parser.ReadFile(Environment.ExpandEnvironmentVariables(Environment.ExpandEnvironmentVariables("%appdata%\\ShareShot\\auth.ini")));
                clientId = authData["credentials"]["client_id"];
            }
            catch (ParsingException) {
                Console.WriteLine("Error: File not found.");
                return(null);
            }

            // Get the authorization url using the clientId
            var client           = new ImgurClient(clientId);
            var endpoint         = new OAuth2Endpoint(client);
            var authorizationUrl = endpoint.GetAuthorizationUrl(OAuth2ResponseType.Token);

            // Create a web driver that will open the authorization url in an instance of Firefox
            IWebDriver driver = new FirefoxDriver {
                Url = authorizationUrl
            };

            // Wait until the user logs in and the browser redirects
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromDays(365));

            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.UrlContains("#access_token="));

            // Get the url of the redirected web page
            string url = driver.Url;

            // Close the IWebDriver
            driver.Close();

            // The url comes with a substring that needs to be deleted
            url = url.Replace("state=#", "");

            // Create a uri using the updated url, then turn it into a functional string that can be queried
            Uri    uri         = new Uri(url);
            string queryString = uri.Query;

            // Get the access and refresh tokens
            string accessToken  = System.Web.HttpUtility.ParseQueryString(queryString).Get("access_token");
            string refreshToken = System.Web.HttpUtility.ParseQueryString(queryString).Get("refresh_token");

            authData["credentials"]["refresh_token"] = refreshToken;
            parser.WriteFile(Environment.ExpandEnvironmentVariables("%appdata%\\ShareShot\\auth.ini"), authData);

            return(accessToken);
        }