Exemplo n.º 1
0
        private async Task Authorize()
        {
            dynamic keys = await GetAppCredentials("Facebook");

            string clientId = keys.client_id;

            IDeviceOAuth2Stepwise auth = new DeviceOAuth(EndPointInfo.Facebook, "public_profile", clientId);
            var info = await auth.StartAuthorization();

            var msg = $"Navigate to {info.VerificationUri} \nEnter this code: {info.UserCode}";

            Notify.Text = msg;

            var token = await auth.WaitForUserConsent(info);

            var defaults = new DynamicRestClientDefaults()
            {
                AuthScheme = "Bearer",
                AuthToken  = token.AccessToken
            };

            dynamic client = new DynamicRestClient("https://graph.facebook.com/v2.3/me", defaults);

            dynamic v = await client.get(fields : "name");

            Notify.Text   = "";
            UserName.Text = v.name;
        }
Exemplo n.º 2
0
        public async Task FacebookAuthStepwise()
        {
            var keys = TestHelpers.GetAppCredentials("Facebook");
            IDeviceOAuth2Stepwise auth = new DeviceOAuth(EndPointInfo.Facebook, (string)keys.scopes, (string)keys.client_id);

            var info = await auth.StartAuthorization();

            TestHelpers.SpawnBrowser(info.VerificationUri, info.UserCode);

            var token = await auth.WaitForUserConsent(info);

            Assert.IsNotNull(token);
            Assert.IsFalse(string.IsNullOrEmpty(token.AccessToken));
        }
Exemplo n.º 3
0
        public async Task FacebookAuth()
        {
            var keys = TestHelpers.GetAppCredentials("Facebook");
            IDeviceOAuth2 auth = new DeviceOAuth(EndPointInfo.Facebook, (string)keys.scopes, (string)keys.client_id);

            auth.PromptUser += (o, e) =>
            {
                TestHelpers.SpawnBrowser(e.VerificationUri, e.UserCode);
            };

            var token = await auth.Authorize(null);

            Assert.IsNotNull(token);
            Assert.IsFalse(string.IsNullOrEmpty(token.AccessToken));
        }
Exemplo n.º 4
0
        public async Task FacebookAuth()
        {
            var           keys = TestHelpers.GetAppCredentials("Facebook");
            IDeviceOAuth2 auth = new DeviceOAuth(EndPointInfo.Facebook, (string)keys.scopes, (string)keys.client_id);

            auth.PromptUser += (o, e) =>
            {
                TestHelpers.SpawnBrowser(e.VerificationUri, e.UserCode);
            };

            var token = await auth.Authorize(null);

            Assert.IsNotNull(token);
            Assert.IsFalse(string.IsNullOrEmpty(token.AccessToken));
        }
Exemplo n.º 5
0
        private static async Task Go(EndPointInfo endpoint)
        {
            var           keys = GetAppCredentials(endpoint.Name);
            IDeviceOAuth2 auth = new DeviceOAuth(endpoint, (string)keys.scopes, (string)keys.client_id, (string)keys.client_secret);

            auth.WaitingForConfirmation += (o, e) =>
            {
                Console.CursorLeft = 0;
                Console.Write(e + " seconds left         ");
            };
            auth.PromptUser += (o, e) =>
            {
                Console.WriteLine("");
                Console.WriteLine("Go to this url on any computer:");
                Console.WriteLine(e.VerificationUri);
                Console.WriteLine("And enter this code:");
                Console.WriteLine(e.UserCode);
                Console.WriteLine("");
            };

            Console.WriteLine("Authenticating...");

            try
            {
                var token = await auth.Authorize(null);

                dynamic profile = await auth.GetProfile(token);

                Console.WriteLine("");
                Console.WriteLine("Name = " + profile.name);
            }
            catch (AggregateException e)
            {
                Console.WriteLine("Error:");
                foreach (var inner in e.InnerExceptions)
                {
                    Console.WriteLine(inner.Message);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error:");
                Console.WriteLine(e.Message);
            }
        }