diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-01-23 22:28:55 +0100 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-01-23 22:28:55 +0100 |
| commit | 253c8479b9ae0ba6853a70728d3f6e904e1ac2ba (patch) | |
| tree | a8d18e650d327221e60bee84879caaabf4f92acf /src/server/Startup.cs | |
| parent | d268ddf7fbb6ef025564c1a6f1d935a1267185df (diff) | |
| download | bookmark-thing-253c8479b9ae0ba6853a70728d3f6e904e1ac2ba.tar.xz bookmark-thing-253c8479b9ae0ba6853a70728d3f6e904e1ac2ba.zip | |
feat: WIP: Add option to login in with github
Diffstat (limited to 'src/server/Startup.cs')
| -rw-r--r-- | src/server/Startup.cs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/server/Startup.cs b/src/server/Startup.cs index 4b7c097..4ad70fc 100644 --- a/src/server/Startup.cs +++ b/src/server/Startup.cs @@ -1,3 +1,5 @@ +using AspNet.Security.OAuth.GitHub; + namespace IOL.BookmarkThing.Server; public class Startup @@ -67,7 +69,10 @@ public class Startup options.WaitForJobsToComplete = true; }); - services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) + services.AddAuthentication(options => { + options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = GitHubAuthenticationDefaults.AuthenticationScheme; + }) .AddCookie(options => { options.Cookie.Name = "bookmarkthing_session"; options.Cookie.SameSite = SameSiteMode.Strict; @@ -81,6 +86,18 @@ public class Startup return Task.FromResult<object>(null); }; }) + // TODO: Handle github claims, current behaviour creates entries with user_id set to default guid :D + .AddGitHub(options => { + options.ClientSecret = Configuration.GetValue<string>("GH_CLIENT_SECRET"); + options.ClientId = Configuration.GetValue<string>("GH_CLIENT_ID"); + options.SaveTokens = true; + options.CorrelationCookie = new CookieBuilder { + Name = "gh_corr", + SameSite = SameSiteMode.Lax, + SecurePolicy = CookieSecurePolicy.Always, + HttpOnly = true, + }; + }) .AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>(Constants.BASIC_AUTH_SCHEME, default); services.AddLogging(); |
