public async Task <IActionResult> Update(string scheme)
        {
            AuthenticationViewModel model;
            var definition = await _manager.FindBySchemeAsync(scheme);

            if (definition == null)
            {
                return(NotFound());
            }
            else
            {
                model = new AuthenticationViewModel
                {
                    Scheme      = definition.Scheme,
                    DisplayName = definition.DisplayName,
                    HandlerType = definition.HandlerType.Name
                };

                var oAuthOptions = definition.Options as OAuthOptions; // GoogleOptions is OAuthOptions
                model.ClientId     = oAuthOptions.ClientId;
                model.ClientSecret = oAuthOptions.ClientSecret;
            }

            return(View(model));
        }
        public async Task Assertions()
        {
            Assert.Throws <ArgumentNullException>(() => new NoPersistentDynamicManager <FakeSchemeDefinition>(null, null, null));
            var schemeProviderMock = new Mock <IAuthenticationSchemeProvider>().Object;

            Assert.Throws <ArgumentNullException>(() => new NoPersistentDynamicManager <FakeSchemeDefinition>(schemeProviderMock, null, null));
            var serviceProviderMock = new Mock <IServiceProvider>().Object;
            var factory             = new OptionsMonitorCacheWrapperFactory(serviceProviderMock);

            Assert.Throws <ArgumentNullException>(() => new NoPersistentDynamicManager <FakeSchemeDefinition>(schemeProviderMock, factory, null));
            var storeMock = new Mock <IDynamicProviderStore <FakeSchemeDefinition> >().Object;
            var manager   = new PersistentDynamicManager <FakeSchemeDefinition>(schemeProviderMock, factory, storeMock, new List <Type>());
            await Assert.ThrowsAsync <ArgumentNullException>(() => manager.AddAsync(null));

            await Assert.ThrowsAsync <ArgumentNullException>(() => manager.UpdateAsync(null));

            await Assert.ThrowsAsync <ArgumentException>(() => manager.RemoveAsync(null));

            await Assert.ThrowsAsync <ArgumentException>(() => manager.RemoveAsync(""));

            await Assert.ThrowsAsync <ArgumentException>(() => manager.RemoveAsync("  "));

            await Assert.ThrowsAsync <ArgumentException>(() => manager.FindBySchemeAsync(null));

            await Assert.ThrowsAsync <ArgumentException>(() => manager.FindBySchemeAsync(""));

            await Assert.ThrowsAsync <ArgumentException>(() => manager.FindBySchemeAsync("  "));
        }
Пример #3
0
        private async Task <SchemeDefinition> GetEntity(string id)
        {
            var definition = await _manager.FindBySchemeAsync(id).ConfigureAwait(false);

            if (definition == null)
            {
                throw new IdentityException($"SchemeDefinition {id} not found");
            }
            return(definition);
        }
Пример #4
0
        internal static void SeedProviders(IConfiguration configuration, PersistentDynamicManager <SchemeDefinition> persistentDynamicManager)
        {
            var googleDefinition = persistentDynamicManager.FindBySchemeAsync("Google").GetAwaiter().GetResult();

            if (googleDefinition == null)
            {
                var options = new Microsoft.AspNetCore.Authentication.Google.GoogleOptions
                {
                    ClientId     = configuration.GetValue <string>("Google:ClientId"),
                    ClientSecret = configuration.GetValue <string>("Google:ClientSecret"),
                };
                persistentDynamicManager.AddAsync(new SchemeDefinition
                {
                    Scheme      = "Google",
                    DisplayName = "Google",
                    HandlerType = persistentDynamicManager.ManagedHandlerType.First(t => t.Name == "GoogleHandler"),
                    Options     = options
                }).ConfigureAwait(false);
            }
        }