public AuthenticationRegistry(IAuthenticationProvider facebookProvider,
                                      IAuthenticationProvider googleProvider,
                                      IAuthenticationProvider twitterProvider)
        {
            var authenticationService = new AuthenticationService();

            if (facebookProvider != null)
            {
                authenticationService.AddProvider(facebookProvider);
            }

            if (googleProvider != null)
            {
                authenticationService.AddProvider(googleProvider);
            }

            if (twitterProvider != null)
            {
                authenticationService.AddProvider(twitterProvider);
            }

            For <IAuthenticationService>()
            .Use(authenticationService);

            For <IAntiForgery>()
            .Use <AntiForgery>();
        }
        public AuthenticationRegistry(IAuthenticationProvider facebookProvider,
                                      IAuthenticationProvider googleProvider,
                                      IAuthenticationProvider twitterProvider)
        {
            var authenticationService = new AuthenticationService();

            if (facebookProvider != null)
            {
                authenticationService.AddProvider(facebookProvider);
            }

            if (googleProvider != null)
            {
                authenticationService.AddProvider(googleProvider);
            }

            if (twitterProvider != null)
            {
                authenticationService.AddProvider(twitterProvider);
            }

            For<IAuthenticationService>()
                .Use(authenticationService)
                .Named("Authentication Service.");
        }
            public void GivenAnExistingProvider_AddProvider_ThrowsAnException()
            {
                // Arrange.
                var authenticationService = new AuthenticationService();
                var facebookProvider = new FacebookProvider("a", "b", new Uri("http://www.google.com"));
                // Act.
                authenticationService.AddProvider(facebookProvider);
                var result = Assert.Throws<AuthenticationException>( 
                    () => authenticationService.AddProvider(facebookProvider));

                // Assert.
                Assert.NotNull(result);
                Assert.Equal("Trying to add a facebook provider, but one already exists.", result.Message);
            }
Example #4
0
            public void GivenAFakeProviderKeyWhichDoesExist_RedirectToAuthenticate_ReturnsAUri()
            {
                // Arrange.
                const string name         = "FakeProviderWoot";
                var          fakeProvider = new FakeProvider(name)
                {
                    AccessToken = new AccessToken
                    {
                        ExpiresOn   = DateTime.Now.AddMinutes(100),
                        PublicToken = "I.Am.A.Public.Token"
                    },
                    UserInformation = new UserInformation
                    {
                        Email    = "*****@*****.**",
                        Gender   = GenderType.Male,
                        Name     = "Fake Name",
                        Id       = "1234567890",
                        UserName = "******"
                    }
                };

                var authenticationService = new AuthenticationService();

                authenticationService.AddProvider(fakeProvider);

                // Act.
                var result = authenticationService.RedirectToAuthenticationProvider(name,
                                                                                    new Uri(
                                                                                        "http://i.want.to.go.home.com/click/feet/together?provider=google"));

                // Assert.
                Assert.NotNull(result);
                Assert.Equal("http://i.want.to.go.home.com/click/feet/together?provider=google&state=This%20is%20some%20fake%20state", result.AbsoluteUri);
            }
        static HomeController()
        {
            // For the purpose of this example we just made the service static in 
            // a static constructor, normally you would do this using dependency injection
            // but for the take of simplicity we added it it here. Please refer
            // to the Advanced sample for the DI version. Don't use a static constructor
            // like this in your project, please. :)
            var facebookProvider = new FacebookProvider(FacebookAppId, FacebookAppSecret);
            var twitterProvider = new TwitterProvider(TwitterConsumerKey, TwitterConsumerSecret);
            var googleProvider = new GoogleProvider(GoogleConsumerKey, GoogleConsumerSecret);

            AuthenticationService = new AuthenticationService();
            AuthenticationService.AddProvider(facebookProvider);
            AuthenticationService.AddProvider(twitterProvider);
            AuthenticationService.AddProvider(googleProvider);
        }
        private static void RegisterAuthenticationProviders(TinyIoCContainer container)
        {
            Condition.Requires(container).IsNotNull();

            var twitterProvider = new TwitterProvider(TwitterConsumerKey, TwitterConsumerSecret);
            var facebookProvider = new FacebookProvider(FacebookAppId, FacebookAppSecret);
            var googleProvider = new GoogleProvider(GoogleConsumerKey, GoogleConsumerSecret);

            var authenticationService = new AuthenticationService();

            authenticationService.AddProvider(twitterProvider);
            authenticationService.AddProvider(facebookProvider);
            authenticationService.AddProvider(googleProvider);

            container.Register<IAuthenticationService>(authenticationService);
        }
        public HomeController()
        {
            var facebookProvider = new FacebookProvider(FacebookAppId, FacebookAppSecret,
                                                        new Uri(
                                                            "http://localhost:1337/home/AuthenticateCallback?providerKey=facebook"));

            var twitterProvider = new TwitterProvider(TwitterConsumerKey, TwitterConsumerSecret,
                                                      new Uri(
                                                          "http://localhost:1337/home/AuthenticateCallback?providerKey=twitter"));

            var googleProvider = new GoogleProvider(GoogleConsumerKey, GoogleConsumerSecret,
                                                    new Uri(
                                                        "http://localhost:1337/home/AuthenticateCallback?providerKey=google"));

            _authenticationService = new AuthenticationService();
            _authenticationService.AddProvider(facebookProvider);
            _authenticationService.AddProvider(twitterProvider);
            _authenticationService.AddProvider(googleProvider);
        }
        public HomeController()
        {
            var facebookProvider =
                new FakeFacebookProvider(new Uri("http://localhost:1338/home/AuthenticateCallback?providerKey=facebook"));
            var twitterProvider =
                new FakeTwitterProvider(new Uri("http://localhost:1338/home/AuthenticateCallback?providerKey=twitter"));
            var googleProvider =
                new FakeGoogleProvider(new Uri("http://localhost:1338/home/AuthenticateCallback?providerKey=google"));

            _authenticationService = new AuthenticationService();
            _authenticationService.AddProvider(facebookProvider);
            _authenticationService.AddProvider(twitterProvider);
            _authenticationService.AddProvider(googleProvider);

            // Some providers that error.
            var facebookProviderThatErrors =
                new FakeFacebookProvider(
                    new Uri("http://localhost:1338/home/AuthenticateCallbackThatErrors?providerKey=facebook"))
            {
                AuthenticateClientExceptionMessage =
                    "ZOMG! Something nasty has occured! ID10T Error!1!1!1. -le sad panda-"
            };
            var twitterProviderThatErrors =
                new FakeTwitterProvider(
                    new Uri("http://localhost:1338/home/AuthenticateCallbackThatErrors?providerKey=twitter"))
            {
                AuthenticateClientExceptionMessage =
                    "ZOMG! Something nasty has occured! ID10T Error!1!1!1. -le sad panda-"
            };
            var googleProviderThatErrors =
                new FakeGoogleProvider(
                    new Uri("http://localhost:1338/home/AuthenticateCallbackThatErrors?providerKey=google"))
            {
                AuthenticateClientExceptionMessage =
                    "ZOMG! Something nasty has occured! ID10T Error!1!1!1. -le sad panda-"
            };

            _authenticationServiceThatErrors = new AuthenticationService();
            _authenticationServiceThatErrors.AddProvider(facebookProviderThatErrors);
            _authenticationServiceThatErrors.AddProvider(twitterProviderThatErrors);
            _authenticationServiceThatErrors.AddProvider(googleProviderThatErrors);
        }
        public HomeController()
        {
            var facebookProvider =
                new FakeFacebookProvider(new Uri("http://localhost:1338/home/AuthenticateCallback?providerKey=facebook"));
            var twitterProvider =
                new FakeTwitterProvider(new Uri("http://localhost:1338/home/AuthenticateCallback?providerKey=twitter"));
            var googleProvider =
                new FakeGoogleProvider(new Uri("http://localhost:1338/home/AuthenticateCallback?providerKey=google"));

            _authenticationService = new AuthenticationService();
            _authenticationService.AddProvider(facebookProvider);
            _authenticationService.AddProvider(twitterProvider);
            _authenticationService.AddProvider(googleProvider);

            // Some providers that error.
            var facebookProviderThatErrors =
                new FakeFacebookProvider(
                    new Uri("http://localhost:1338/home/AuthenticateCallbackThatErrors?providerKey=facebook"))
                {
                    AuthenticateClientExceptionMessage =
                        "ZOMG! Something nasty has occured! ID10T Error!1!1!1. -le sad panda-"
                };
            var twitterProviderThatErrors =
                new FakeTwitterProvider(
                    new Uri("http://localhost:1338/home/AuthenticateCallbackThatErrors?providerKey=twitter"))
                {
                    AuthenticateClientExceptionMessage =
                        "ZOMG! Something nasty has occured! ID10T Error!1!1!1. -le sad panda-"
                };
            var googleProviderThatErrors =
                new FakeGoogleProvider(
                    new Uri("http://localhost:1338/home/AuthenticateCallbackThatErrors?providerKey=google"))
                {
                    AuthenticateClientExceptionMessage =
                        "ZOMG! Something nasty has occured! ID10T Error!1!1!1. -le sad panda-"
                };

            _authenticationServiceThatErrors = new AuthenticationService();
            _authenticationServiceThatErrors.AddProvider(facebookProviderThatErrors);
            _authenticationServiceThatErrors.AddProvider(twitterProviderThatErrors);
            _authenticationServiceThatErrors.AddProvider(googleProviderThatErrors);
        }
            public void GivenAValidProviderKeyWithNoState_RedirectToAuthenticate_ReturnsAUri()
            {
                // Arrange.
                var authenticationService = new AuthenticationService();
                authenticationService.AddProvider(new FacebookProvider("aa", "bb", new Uri("http://www.whatever.com")));

                // Act.
                var result = authenticationService.RedirectToAuthenticationProvider("Facebook");

                // Assert.
                Assert.NotNull(result);
                Assert.Equal("https://www.facebook.com/dialog/oauth?client_id=aa&scope=email&redirect_uri=http://www.whatever.com/", result.AbsoluteUri);
            }
        static HomeController()
        {
            // For the purpose of this example we just made the service static in
            // a static constructor, normally you would do this using dependency injection
            // but for the take of simplicity we added it it here. Please refer
            // to the Advanced sample for the DI version. Don't use a static constructor
            // like this in your project, please. :)
            var facebookProvider = new FacebookProvider(new ProviderParams {
                Key = FacebookAppId, Secret = FacebookAppSecret
            });
            var twitterProvider = new TwitterProvider(new ProviderParams {
                Key = TwitterConsumerKey, Secret = TwitterConsumerSecret
            });
            var googleProvider = new GoogleProvider(new ProviderParams {
                Key = GoogleConsumerKey, Secret = GoogleConsumerSecret
            });

            AuthenticationService = new AuthenticationService();
            AuthenticationService.AddProvider(facebookProvider);
            AuthenticationService.AddProvider(twitterProvider);
            AuthenticationService.AddProvider(googleProvider);
        }
        private static void RegisterAuthenticationProviders(TinyIoCContainer container)
        {
            Condition.Requires(container).IsNotNull();

            var twitterProvider = new TwitterProvider(TwitterConsumerKey, TwitterConsumerSecret,
                                                      new Uri(
                                                          "http://localhost:6969/AuthenticateCallback?providerKey=Twitter"));

            var facebookProvider = new FacebookProvider(FacebookAppId, FacebookAppSecret,
                                                        new Uri(
                                                            "http://localhost:6969/AuthenticateCallback?providerKey=facebook"));

            var googleProvider = new GoogleProvider(GoogleConsumerKey, GoogleConsumerSecret,
                                                    new Uri(
                                                        "http://localhost:6969/AuthenticateCallback?providerKey=google"));

            var authenticationService = new AuthenticationService();
            authenticationService.AddProvider(twitterProvider);
            authenticationService.AddProvider(facebookProvider);
            authenticationService.AddProvider(googleProvider);

            container.Register<IAuthenticationService>(authenticationService);
        }
            public void GivenAnExistingProvider_AddProvider_ThrowsAnException()
            {
                // Arrange.
                var authenticationService = new AuthenticationService();
                var facebookProvider = new FacebookProvider(new ProviderParams { Key = "a", Secret = "b" });

                // Act.
                var result = Assert.Throws<WorldDominationConfigurationException>(
                    () => authenticationService.AddProvider(facebookProvider, false));

                // Assert.
                Assert.NotNull(result);
                Assert.Equal("The provider 'Facebook' already exists and cannot be overridden, either set `replaceExisting` to `true`, or remove the provider first.", result.Message);
            }
            public void GivenAnExistingProvider_AddProvider_ThrowsAnException()
            {
                // Arrange.
                var authenticationService = new AuthenticationService();
                var facebookProvider = new FacebookProvider(new ProviderParams { Key = "a", Secret = "b" });

                // Act.
                var result = Assert.Throws<AuthenticationException>(
                    () => authenticationService.AddProvider(facebookProvider));

                // Assert.
                Assert.NotNull(result);
                Assert.Equal("Trying to add a facebook provider, but one already exists.", result.Message);
            }
            public void GivenANewProvider_AddProvider_AddsTheProviderToTheProviderCollection()
            {
                // Arrange.
                var authenticationService = new AuthenticationService();

                // Act.
                authenticationService.AddProvider(new TwitterProvider("a", "b"));

                // Assert.
                var providers = authenticationService.AuthenticationProviders;
                Assert.NotNull(providers);
                Assert.Equal(3, providers.Count);
                Assert.NotNull(providers["twitter"]);
            }
            public void GivenANewProvider_AddProvider_AddsTheProviderToTheProviderCollection()
            {
                // Arrange.
                var authenticationService = new AuthenticationService();

                // Act.
                authenticationService.AddProvider(new FacebookProvider("a", "b", new Uri("http://www.google.com")));

                // Assert.
                var providers = authenticationService.AuthenticationProviders;
                Assert.NotNull(providers);
                Assert.Equal(1, providers.Count);
                Assert.NotNull(providers["facebook"]);
            }
Example #17
0
            public void GivenAnExistingProvider_AddProvider_ThrowsAnException()
            {
                // Arrange.
                var authenticationService = new AuthenticationService();
                var facebookProvider      = new FacebookProvider(new ProviderParams {
                    Key = "a", Secret = "b"
                });

                // Act.
                var result = Assert.Throws <InvalidOperationException>(
                    () => authenticationService.AddProvider(facebookProvider, false));

                // Assert.
                Assert.NotNull(result);
                Assert.Equal("The provider 'Facebook' already exists and cannot be overridden, either set `replaceExisting` to `true`, or remove the provider first.", result.Message);
            }
Example #18
0
            public void GivenANewProvider_AddProvider_AddsTheProviderToTheProviderCollection()
            {
                // Arrange.
                var authenticationService = new AuthenticationService();

                // Act.
                authenticationService.AddProvider(new TwitterProvider(new ProviderParams {
                    Key = "a", Secret = "b"
                }));

                // Assert.
                var providers = authenticationService.AuthenticationProviders;

                Assert.NotNull(providers);
                Assert.Equal(3, providers.Count);
                Assert.NotNull(providers["twitter"]);
            }
Example #19
0
        protected override void ConfigureApplicationContainer(TinyIoCContainer container)
        {
            base.ConfigureApplicationContainer(container);

            var githubProvider =
                new GitHubProvider(new ProviderParams()
            {
                Key = GithubConsumerKey, Secret = GithubConsumerSecret
            });

            ((WorldDomination.Web.Authentication.ExtraProviders.GitHub.GitHubAuthenticationServiceSettings)
             githubProvider.DefaultAuthenticationServiceSettings).Scope = "user:email,public_repo";

            var authenticationService = new AuthenticationService();

            authenticationService.AddProvider(githubProvider);

            container.Register <IAuthenticationService>(authenticationService);
        }
            public void GivenAFakeProviderKeyWhichDoesExist_RedirectToAuthenticate_ReturnsAUri()
            {
                // Arrange.
                const string name = "FakeProviderWoot";
                var fakeProvider = new FakeProvider(name)
                {
                    AccessToken = new AccessToken
                    {
                        ExpiresOn = DateTime.Now.AddMinutes(100),
                        PublicToken = "I.Am.A.Public.Token"
                    },
                    UserInformation = new UserInformation
                    {
                        Email = "*****@*****.**",
                        Gender = GenderType.Male,
                        Name = "Fake Name",
                        Id = "1234567890",
                        UserName = "******"
                    }
                };

                var authenticationService = new AuthenticationService();
                authenticationService.AddProvider(fakeProvider);

                // Act.
                var result = authenticationService.RedirectToAuthenticationProvider(name,
                                                                       new Uri(
                                                                           "http://i.want.to.go.home.com/click/feet/together?provider=google"));

                // Assert.
                Assert.NotNull(result);
                Assert.Equal("http://i.want.to.go.home.com/click/feet/together?provider=google&state=This%20is%20some%20fake%20state", result.AbsoluteUri);
            }