Beispiel #1
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));
        }
Beispiel #2
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));
        }
Beispiel #3
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);
            }
        }