Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class Users
- {
- public static List<InMemoryUser> Get()
- {
- return new List<InMemoryUser>
- {
- new InMemoryUser
- {
- Username = "Bob",Password = "password",Subject = "1",
- Claims = new []
- {
- new Claim(Constants.ClaimTypes.GivenName,"firstName"),
- new Claim(Constants.ClaimTypes.FamilyName,"lastName")
- }
- }
- };
- }
- }
- public static class Clients
- {
- public static IEnumerable<Client> Get()
- {
- return new[]
- {
- new Client
- {
- ClientId = "MVC",
- ClientName = "MVC Client Name",
- RedirectUris = new List<string>
- {
- "https://localhost:44302/"
- },
- Flow = Flows.Implicit,
- AllowAccessToAllScopes = true
- }
- };
- }
- }
- public void Configuration(IAppBuilder app)
- {
- JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
- app.Map("/identity", appBuilder => {
- appBuilder.UseIdentityServer(new IdentityServer3.Core.Configuration.IdentityServerOptions
- {
- SiteName = "Site Name",
- SigningCertificate = LoadCertificate(),
- RequireSsl = false,
- Factory = new IdentityServer3.Core.Configuration.IdentityServerServiceFactory()
- .UseInMemoryClients(Clients.Get())
- .UseInMemoryUsers(Users.Get())
- .UseInMemoryScopes(StandardScopes.All)
- });
- });
- app.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions
- {
- AuthenticationType = "Cookies"
- });
- app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
- {
- Authority = "https://localhost:44302/identity",
- ClientId = "MVC",
- RedirectUri = "https://localhost:44302/",
- ResponseType = "id_token",
- SignInAsAuthenticationType = "Cookies",
- Scope = "openid profile"
- });
- }
- [Authorize]
- public ActionResult Contact()
- {
- ClaimsPrincipal principal = User as ClaimsPrincipal;
- return View(principal.Claims);
- }
- @model IEnumerable<System.Security.Claims.Claim>
- @foreach (var item in Model)
- {
- <div>
- <span>@item.Type</span>
- <span>@item.Value</span>
- </div>
- }
- </div>
- public static IEnumerable<Client> Get()
- {
- return new[]
- {
- new Client
- {
- ClientId = "MVC",
- ClientName = "MVC Client Name",
- RedirectUris = new List<string>
- {
- "https://localhost:44302/"
- },
- Flow = Flows.Hybrid,//Changed this to Hybrid
- AllowAccessToAllScopes = true
- }
- };
- }
- app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
- {
- Authority = "https://localhost:44302/identity",
- ClientId = "MVC",
- RedirectUri = "https://localhost:44302/",
- ResponseType = "code id_token token", //Changed response type
- SignInAsAuthenticationType = "Cookies",
- Scope = "openid profile"
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement