-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDependencyInjection.cs
More file actions
40 lines (33 loc) · 1.22 KB
/
Copy pathDependencyInjection.cs
File metadata and controls
40 lines (33 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using BareMinimumGoogleAuth.Data;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.Google;
using Microsoft.EntityFrameworkCore;
namespace BareMinimumGoogleAuth
{
public static class DependencyInjection
{
public static IServiceCollection AddGoogleConfiguration(this IServiceCollection services, IConfiguration cfg)
{
var google = cfg.GetSection("Google");
services.AddAuthentication(opt =>
{
opt.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
opt.DefaultChallengeScheme = GoogleDefaults.AuthenticationScheme;
}).AddCookie()
.AddGoogle(opt =>
{
opt.ClientId = google["ClientId"]!;
opt.ClientSecret = google["ClientSecret"]!;
});
return services;
}
public static IServiceCollection AddDatabaseContext(this IServiceCollection services , IConfiguration cfg)
{
services.AddDbContext<GoogleContext>(opt =>
{
opt.UseNpgsql(cfg.GetConnectionString("DefaultConnection"));
});
return services;
}
}
}