Guest User

Untitled

a guest
Apr 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. services.AddAuthentication(sharedOptions =>
  2. {
  3. sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
  4. sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
  5.  
  6. })
  7. .AddOpenIdConnect(options =>
  8. {
  9. options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
  10. options.Authority = authConfig.GetValue<string>("Authority");
  11. options.RequireHttpsMetadata = false;
  12. options.ClientId = authConfig.GetValue<string>("ClientId");
  13. options.ClientSecret = authConfig.GetValue<string>("ClientSecret");
  14. options.ResponseType = "code id_token token";
  15. options.SaveTokens = true;
  16. options.GetClaimsFromUserInfoEndpoint = false;
  17. options.TokenValidationParameters = new
  18. TokenValidationParameters
  19. {
  20. NameClaimType = ClaimTypes.Name,
  21. RoleClaimType = ClaimTypes.Role
  22. };
  23. options.Events = new OpenIdConnectEvents
  24. {
  25. OnRemoteFailure = context =>
  26. {
  27. context.HttpContext.Response.Redirect($"/Error?RequestId=4000&errormessage={context.Failure?.Message }");
  28. context.HandleResponse();
  29. return Task.FromResult(0);
  30. },
  31. OnRedirectToIdentityProvider = context =>
  32. {
  33. //TODO: Get IdentityProvider value for Multiple subscribers and not from config
  34. var idp = authConfig.GetValue<string>("IdentityProvider");
  35. var acrValues = new List<string>();
  36.  
  37. if (!string.IsNullOrWhiteSpace(idp))
  38. acrValues.Add($"idp:{idp}");
  39.  
  40. if (acrValues.Count > 0)
  41. context.ProtocolMessage.AcrValues = string.Join(" ", acrValues);
  42.  
  43. //if (context.ProtocolMessage.RequestType != OpenIdConnectRequestType.Logout)
  44. //{
  45. // if (!CurrentEnvironment.IsDevelopment() &&
  46. // context.ProtocolMessage.RequestType == OpenIdConnectRequestType.Authentication)
  47. // {
  48. // // in widget iframe skip prompt login screen
  49. // context.ProtocolMessage.Prompt = "none";
  50. // }
  51. // return Task.FromResult(0);
  52. //}
  53.  
  54. var idTokenHint = context.HttpContext.User.FindFirst("id_token");
  55. if (idTokenHint != null)
  56. context.ProtocolMessage.IdTokenHint = idTokenHint.Value;
  57.  
  58. return Task.FromResult(0);
  59. }
  60.  
  61. "ClientName": "SampleApp",
  62. "ClientId": "sample.app.mvc",
  63. "Flow": 2,
  64. "RedirectUris": ["https://localhost:44368/signin-oidc","https://ecare-rooster-test.azurewebsites.net/signin-oidc"],
  65. "PostLogoutRedirectUris": ["https://localhost:44368/"],
  66. "PrefixClientClaims": true,
  67. "RequireConsent": false,
  68. "AllowedScopes":
  69. [
  70. "openid",
  71. "profile",
  72. "roles",
  73. "CustomScope"
  74. ],
  75. "Claims": [{
  76. "Type": "subscriberId",
  77. "Value": "35621957-cb82-4ecc-bce5-836c707d163c"
  78. }],
  79. "ClientSecrets": [{
  80. "Secret": "tudc73K2y7pnEjT2"
  81. }],
  82.  
  83. "IdentityTokenLifetime": 300,
  84. "AccessTokenLifetime": 3600,
  85. "AuthorizationCodeLifetime": 300,
  86. "EnableLocalLogin": true
  87. }
Add Comment
Please, Sign In to add comment