Last active
May 16, 2019 01:52
-
-
Save himadric/33313b40925892c66901cd3786adb4d4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using Microsoft.AspNetCore.Authentication; | |
using Microsoft.AspNetCore.Authentication.OpenIdConnect; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Logging; | |
using Sitecore.Framework.Runtime.Configuration; | |
using Sitecore.Plugin.IdentityProvider.Ids4Demo.Configuration; | |
using System; | |
using System.Security.Claims; | |
using System.Threading.Tasks; | |
namespace Sitecore.Plugin.IdentityProvider.Ids4Demo | |
{ | |
public class ConfigureSitecore | |
{ | |
private readonly ILogger<ConfigureSitecore> _logger; | |
private readonly AppSettings _appSettings; | |
public ConfigureSitecore(ISitecoreConfiguration scConfig, ILogger<ConfigureSitecore> logger) | |
{ | |
this._logger = logger; | |
this._appSettings = new AppSettings(); | |
scConfig.GetSection(AppSettings.SectionName); | |
scConfig.GetSection(AppSettings.SectionName).Bind((object)this._appSettings.Ids4DemoIdentityProvider); | |
} | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
Ids4DemoIdentityProvider ids4DemoProvider = this._appSettings.Ids4DemoIdentityProvider; | |
if (!ids4DemoProvider.Enabled) | |
return; | |
this._logger.LogDebug("Configure '" + ids4DemoProvider.DisplayName + "'. AuthenticationScheme = " + ids4DemoProvider.AuthenticationScheme + ", ClientId = " + ids4DemoProvider.ClientId, Array.Empty<object>()); | |
new AuthenticationBuilder(services).AddOpenIdConnect(ids4DemoProvider.AuthenticationScheme, ids4DemoProvider.DisplayName, (Action<OpenIdConnectOptions>)(options => | |
{ | |
options.SignInScheme = "idsrv.external"; | |
options.ClientId = ids4DemoProvider.ClientId; | |
options.Authority = "https://demo.identityserver.io/"; | |
options.MetadataAddress = ids4DemoProvider.MetadataAddress; | |
options.CallbackPath = "/signin-idsrv"; | |
options.Events.OnRedirectToIdentityProvider += (Func<RedirectContext, Task>)(context => | |
{ | |
Claim first = context.HttpContext.User.FindFirst("idp"); | |
if (string.Equals(first != null ? first.Value : (string)null, ids4DemoProvider.AuthenticationScheme, StringComparison.Ordinal)) | |
context.ProtocolMessage.Prompt = "select_account"; | |
return Task.CompletedTask; | |
}); | |
})); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment