Advertisement
Guest User

Untitled

a guest
Sep 21st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. public static class Users
  2. {
  3. public static List<InMemoryUser> Get()
  4. {
  5. return new List<InMemoryUser>
  6. {
  7. new InMemoryUser
  8. {
  9. Username = "Bob",Password = "password",Subject = "1",
  10. Claims = new []
  11. {
  12. new Claim(Constants.ClaimTypes.GivenName,"firstName"),
  13. new Claim(Constants.ClaimTypes.FamilyName,"lastName")
  14. }
  15. }
  16. };
  17. }
  18. }
  19. public static class Clients
  20. {
  21. public static IEnumerable<Client> Get()
  22. {
  23. return new[]
  24. {
  25. new Client
  26. {
  27. ClientId = "MVC",
  28. ClientName = "MVC Client Name",
  29. RedirectUris = new List<string>
  30. {
  31. "https://localhost:44302/"
  32. },
  33. Flow = Flows.Implicit,
  34. AllowAccessToAllScopes = true
  35. }
  36. };
  37. }
  38. }
  39.  
  40. public void Configuration(IAppBuilder app)
  41. {
  42. JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
  43.  
  44. app.Map("/identity", appBuilder => {
  45. appBuilder.UseIdentityServer(new IdentityServer3.Core.Configuration.IdentityServerOptions
  46. {
  47. SiteName = "Site Name",
  48. SigningCertificate = LoadCertificate(),
  49. RequireSsl = false,
  50. Factory = new IdentityServer3.Core.Configuration.IdentityServerServiceFactory()
  51. .UseInMemoryClients(Clients.Get())
  52. .UseInMemoryUsers(Users.Get())
  53. .UseInMemoryScopes(StandardScopes.All)
  54. });
  55. });
  56.  
  57. app.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions
  58. {
  59. AuthenticationType = "Cookies"
  60. });
  61.  
  62. app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
  63. {
  64. Authority = "https://localhost:44302/identity",
  65. ClientId = "MVC",
  66. RedirectUri = "https://localhost:44302/",
  67. ResponseType = "id_token",
  68. SignInAsAuthenticationType = "Cookies",
  69. Scope = "openid profile"
  70. });
  71. }
  72.  
  73. [Authorize]
  74. public ActionResult Contact()
  75. {
  76. ClaimsPrincipal principal = User as ClaimsPrincipal;
  77. return View(principal.Claims);
  78. }
  79.  
  80. @model IEnumerable<System.Security.Claims.Claim>
  81. @foreach (var item in Model)
  82. {
  83. <div>
  84. <span>@item.Type</span>
  85. <span>@item.Value</span>
  86. </div>
  87. }
  88. </div>
  89.  
  90. public static IEnumerable<Client> Get()
  91. {
  92. return new[]
  93. {
  94. new Client
  95. {
  96. ClientId = "MVC",
  97. ClientName = "MVC Client Name",
  98. RedirectUris = new List<string>
  99. {
  100. "https://localhost:44302/"
  101. },
  102. Flow = Flows.Hybrid,//Changed this to Hybrid
  103. AllowAccessToAllScopes = true
  104. }
  105. };
  106. }
  107.  
  108. app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
  109. {
  110. Authority = "https://localhost:44302/identity",
  111. ClientId = "MVC",
  112. RedirectUri = "https://localhost:44302/",
  113. ResponseType = "code id_token token", //Changed response type
  114. SignInAsAuthenticationType = "Cookies",
  115. Scope = "openid profile"
  116. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement