本文整理汇总了C#中IServiceCollection.ConfigureGoogleAuthentication方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.ConfigureGoogleAuthentication方法的具体用法?C# IServiceCollection.ConfigureGoogleAuthentication怎么用?C# IServiceCollection.ConfigureGoogleAuthentication使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceCollection
的用法示例。
在下文中一共展示了IServiceCollection.ConfigureGoogleAuthentication方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.Get("Data:IdentityConnection:ConnectionString")));
services.Configure<IdentityDbContextOptions>(options =>
{
options.DefaultAdminUserName = Configuration.Get("DefaultAdminUsername");
options.DefaultAdminPassword = Configuration.Get("DefaultAdminPassword");
});
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.ConfigureFacebookAuthentication(options =>
{
options.AppId = "901611409868059";
options.AppSecret = "4aa3c530297b1dcebc8860334b39668b";
});
services.ConfigureGoogleAuthentication(options =>
{
options.ClientId = "514485782433-fr3ml6sq0imvhi8a7qir0nb46oumtgn9.apps.googleusercontent.com";
options.ClientSecret = "V2nDD9SkFbvLTqAUBWBBxYAL";
});
services.ConfigureTwitterAuthentication(options =>
{
options.ConsumerKey = "BSdJJ0CrDuvEhpkchnukXZBUv";
options.ConsumerSecret = "xKUNuKhsRdHD03eLn67xhPAyE1wFFEndFo1X2UJaK2m1jdAxf4";
});
services.AddMvc();
}
示例2: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add EF services to the services container.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<NerdDinnerDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddScoped<INerdDinnerRepository, NerdDinnerRepository>();
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<NerdDinnerDbContext>()
.AddDefaultTokenProviders();
services.ConfigureFacebookAuthentication(options =>
{
options.ClientId = Configuration["Authentication:Facebook:AppId"];
options.ClientSecret = Configuration["Authentication:Facebook:AppSecret"];
});
services.ConfigureGoogleAuthentication(options =>
{
options.ClientId = Configuration["Authentication:Google:AppId"];
options.ClientSecret = Configuration["Authentication:Google:AppSecret"];
});
services.ConfigureTwitterAuthentication(options =>
{
options.ConsumerKey = Configuration["Authentication:Twitter:AppId"];
options.ConsumerSecret = Configuration["Authentication:Twitter:AppSecret"];
});
//services.ConfigureMicrosoftAccountAuthentication(options =>
//{
// options.Caption = "MicrosoftAccount - Requires project changes";
// options.ClientId = Configuration["Authentication:Microsoft:AppId"];
// options.ClientSecret = Configuration["Authentication:Microsoft:AppSecret"];
//});
// Add MVC services to the services container.
services.AddMvc().Configure<MvcOptions>(options =>
{
var settings = new JsonSerializerSettings()
{
Formatting = Formatting.Indented,
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
var formatter = new JsonOutputFormatter { SerializerSettings = settings };
options.OutputFormatters.Insert(0, formatter);
// Add validation filters
options.Filters.Add(new ValidateModelFilterAttribute());
});
}
示例3: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add Application settings to the services container.
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
// Add EF services to the services container.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<UnicornStoreContext>(options => options.UseSqlServer(Configuration["ConnectionStrings:UnicornStore"]))
.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration["ConnectionStrings:UnicornStore"]));
services.AddSingleton<CategoryCache>();
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
// See comments in config.json for info on enabling Facebook auth
var facebookId = Configuration.Get("Secrets:Facebook:AppId");
var facebookSecret = Configuration.Get("Secrets:Facebook:AppSecret");
if (!string.IsNullOrWhiteSpace(facebookId) && !string.IsNullOrWhiteSpace(facebookSecret))
{
_useFacebookAuth = true;
services.ConfigureFacebookAuthentication(options =>
{
options.AppId = facebookId;
options.AppSecret = facebookSecret;
});
}
// See comments in config.json for info on enabling Google auth
var googleId = Configuration.Get("Secrets:Google:ClientId");
var googleSecret = Configuration.Get("Secrets:Google:ClientSecret");
if (!string.IsNullOrWhiteSpace(googleId) && !string.IsNullOrWhiteSpace(googleSecret))
{
_useGoogleAuth = true;
services.ConfigureGoogleAuthentication(options =>
{
options.ClientId = googleId;
options.ClientSecret = googleSecret;
});
}
// Add MVC services to the services container.
services.AddMvc();
// Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
// You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
// services.AddWebApiConventions();
}
示例4: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.Configure<AppSettings>(Configuration.GetConfigurationSection("AppSettings"));
var useInMemoryStore = _platform.IsRunningOnMono || _platform.IsRunningOnNanoServer;
// Add EF services to the services container
if (useInMemoryStore)
{
services.AddEntityFramework()
.AddInMemoryDatabase()
.AddDbContext<MusicStoreContext>(options =>
options.UseInMemoryDatabase());
}
else
{
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MusicStoreContext>(options =>
options.UseSqlServer(Configuration.Get("Data:DefaultConnection:ConnectionString")));
}
// Add Identity services to the services container
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<MusicStoreContext>()
.AddDefaultTokenProviders();
services.ConfigureCookieAuthentication(options =>
{
options.AccessDeniedPath = new PathString("/Home/AccessDenied");
});
services.ConfigureFacebookAuthentication(options =>
{
options.AppId = "550624398330273";
options.AppSecret = "10e56a291d6b618da61b1e0dae3a8954";
});
services.ConfigureGoogleAuthentication(options =>
{
options.ClientId = "977382855444.apps.googleusercontent.com";
options.ClientSecret = "NafT482F70Vjj_9q1PU4B0pN";
});
services.ConfigureTwitterAuthentication(options =>
{
options.ConsumerKey = "9J3j3pSwgbWkgPFH7nAf0Spam";
options.ConsumerSecret = "jUBYkQuBFyqp7G3CUB9SW3AfflFr9z3oQBiNvumYy87Al0W4h8";
});
services.ConfigureMicrosoftAccountAuthentication(options =>
{
options.Caption = "MicrosoftAccount - Requires project changes";
options.ClientId = "000000004012C08A";
options.ClientSecret = "GaMQ2hCnqAC6EcDLnXsAeBVIJOLmeutL";
});
services.ConfigureCors(options =>
{
options.AddPolicy("CorsPolicy", builder =>
{
builder.WithOrigins("http://example.com");
});
});
// Add MVC services to the services container
services.AddMvc();
//Add all SignalR related services to IoC.
services.AddSignalR();
//Add InMemoryCache
services.AddSingleton<IMemoryCache, MemoryCache>();
// Add session related services.
services.AddCaching();
services.AddSession();
// Add the system clock service
services.AddSingleton<ISystemClock, SystemClock>();
// Configure Auth
services.Configure<AuthorizationOptions>(options =>
{
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
});
}
示例5: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.Configure<AppSettings>(Configuration.GetConfigurationSection("AppSettings"));
//Sql client not available on mono
string value;
var useInMemoryStore = Configuration.TryGet("UseInMemoryStore", out value) && value == "true" ?
true :
_runtimeEnvironment.RuntimeType.Equals("Mono", StringComparison.OrdinalIgnoreCase);
// Add EF services to the services container
if (useInMemoryStore)
{
services.AddEntityFramework()
.AddInMemoryDatabase()
.AddDbContext<MusicStoreContext>(options =>
options.UseInMemoryDatabase());
}
else
{
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MusicStoreContext>(options =>
options.UseSqlServer(Configuration.Get("Data:DefaultConnection:ConnectionString")));
}
// Add Identity services to the services container
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<MusicStoreContext>()
.AddDefaultTokenProviders();
services.ConfigureCookieAuthentication(options =>
{
options.AccessDeniedPath = new PathString("/Home/AccessDenied");
});
services.ConfigureFacebookAuthentication(options =>
{
options.AppId = "[AppId]";
options.AppSecret = "[AppSecret]";
options.Notifications = new OAuthAuthenticationNotifications()
{
OnAuthenticated = FacebookNotifications.OnAuthenticated,
OnReturnEndpoint = FacebookNotifications.OnReturnEndpoint,
OnApplyRedirect = FacebookNotifications.OnApplyRedirect
};
options.BackchannelHttpHandler = new FacebookMockBackChannelHttpHandler();
options.StateDataFormat = new CustomStateDataFormat();
options.Scope.Add("email");
options.Scope.Add("read_friendlists");
options.Scope.Add("user_checkins");
});
services.ConfigureGoogleAuthentication(options =>
{
options.ClientId = "[ClientId]";
options.ClientSecret = "[ClientSecret]";
options.AccessType = "offline";
options.Notifications = new OAuthAuthenticationNotifications()
{
OnAuthenticated = GoogleNotifications.OnAuthenticated,
OnReturnEndpoint = GoogleNotifications.OnReturnEndpoint,
OnApplyRedirect = GoogleNotifications.OnApplyRedirect
};
options.StateDataFormat = new CustomStateDataFormat();
options.BackchannelHttpHandler = new GoogleMockBackChannelHttpHandler();
});
services.ConfigureTwitterAuthentication(options =>
{
options.ConsumerKey = "[ConsumerKey]";
options.ConsumerSecret = "[ConsumerSecret]";
options.Notifications = new TwitterAuthenticationNotifications()
{
OnAuthenticated = TwitterNotifications.OnAuthenticated,
OnReturnEndpoint = TwitterNotifications.OnReturnEndpoint,
OnApplyRedirect = TwitterNotifications.OnApplyRedirect
};
options.StateDataFormat = new CustomTwitterStateDataFormat();
options.BackchannelHttpHandler = new TwitterMockBackChannelHttpHandler();
#if DNX451
options.BackchannelCertificateValidator = null;
#endif
});
services.ConfigureMicrosoftAccountAuthentication(options =>
{
options.Caption = "MicrosoftAccount - Requires project changes";
options.ClientId = "[ClientId]";
options.ClientSecret = "[ClientSecret]";
options.Notifications = new OAuthAuthenticationNotifications()
{
OnAuthenticated = MicrosoftAccountNotifications.OnAuthenticated,
OnReturnEndpoint = MicrosoftAccountNotifications.OnReturnEndpoint,
OnApplyRedirect = MicrosoftAccountNotifications.OnApplyRedirect
};
options.BackchannelHttpHandler = new MicrosoftAccountMockBackChannelHandler();
options.StateDataFormat = new CustomStateDataFormat();
options.Scope.Add("wl.basic");
options.Scope.Add("wl.signin");
//.........这里部分代码省略.........
示例6: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
//Sql client not available on mono
var useInMemoryStore = Type.GetType("Mono.Runtime") != null;
// Add EF services to the services container
if (useInMemoryStore)
{
services.AddEntityFramework()
.AddInMemoryStore()
.AddDbContext<MusicStoreContext>();
}
else
{
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MusicStoreContext>(options =>
options.UseSqlServer(Configuration.Get("Data:DefaultConnection:ConnectionString")));
}
// Add Identity services to the services container
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<MusicStoreContext>()
.AddDefaultTokenProviders();
services.ConfigureFacebookAuthentication(options =>
{
options.AppId = "550624398330273";
options.AppSecret = "10e56a291d6b618da61b1e0dae3a8954";
});
services.ConfigureGoogleAuthentication(options =>
{
options.ClientId = "977382855444.apps.googleusercontent.com";
options.ClientSecret = "NafT482F70Vjj_9q1PU4B0pN";
});
services.ConfigureTwitterAuthentication(options =>
{
options.ConsumerKey = "9J3j3pSwgbWkgPFH7nAf0Spam";
options.ConsumerSecret = "jUBYkQuBFyqp7G3CUB9SW3AfflFr9z3oQBiNvumYy87Al0W4h8";
});
services.ConfigureMicrosoftAccountAuthentication(options =>
{
options.Caption = "MicrosoftAccount - Requires project changes";
options.ClientId = "000000004012C08A";
options.ClientSecret = "GaMQ2hCnqAC6EcDLnXsAeBVIJOLmeutL";
});
// Add MVC services to the services container
services.AddMvc();
//Add all SignalR related services to IoC.
services.AddSignalR();
//Add InMemoryCache
services.AddSingleton<IMemoryCache, MemoryCache>();
// Add session related services.
services.AddCaching();
services.AddSession();
// Configure Auth
services.Configure<AuthorizationOptions>(options =>
{
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
});
}