Last active
September 27, 2018 14:49
-
-
Save victorjonsson/e61aa237201e6a3e5e3f88f59e3760a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Controller exempel | |
public class AccountController : Controller | |
{ | |
public async Task<IActionResult> kollaStatusPåBankIdInloggningen(string reference) { | |
// ... massa saker händer... | |
AuthResult result = authClient.AuthorizeReference(...) | |
// Allt har gått bra, då loggar vi in i mvc-appen | |
ClaimsIdentity identity = new ClaimsIdentity(result.CustomClaims, CookieAuthenticationDefaults.AuthenticationScheme); | |
ClaimsPrincipal principal = new ClaimsPrincipal(identity); | |
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal); | |
// Returnera status 200 | |
} | |
} | |
// startup exempel | |
public void ConfigureServices(IServiceCollection services) { | |
// massa grejer i startup... | |
services.AddAuthentication(options => { | |
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; | |
}) | |
.AddCookie(options => | |
{ | |
options.ExpireTimeSpan = TimeSpan.FromYears(100); // Att fundera över hur länge man är inloggad. | |
options.Cookie.Name = "login"; | |
}); | |
} | |
// Profilservice | |
public class ProfileService : IProfileService | |
{ | |
public ProfileService() | |
{ | |
} | |
public Task GetProfileDataAsync(ProfileDataRequestContext context) | |
{ | |
// Flytta över claims från den inloggade till kontexten som används för att skapa jwt | |
context.IssuedClaims.AddRange(context.Subject.Claims); | |
return Task.FromResult(0); | |
} | |
public Task IsActiveAsync(IsActiveContext context) | |
{ | |
context.IsActive = true; | |
return Task.FromResult(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment