Skip to content

Instantly share code, notes, and snippets.

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;
<?xml version="1.0" encoding="utf-8"?>
<Settings>
<Sitecore>
<ExternalIdentityProviders>
<IdentityProviders>
<Ids4Demo type="Sitecore.Plugin.IdentityProviders.IdentityProvider, Sitecore.Plugin.IdentityProviders">
<AuthenticationScheme>IdS4-Ids4Demo</AuthenticationScheme>
<DisplayName>IdentityServer Demo Identity Provider</DisplayName>
<Enabled>true</Enabled>
<ClientId>implicit</ClientId>
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace SitecoreApi
{
[Route("sitecorelayout")]
[Authorize]
using Clients;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace SitecoreApi
{
public class Startup
[Authorize]
public async Task<IActionResult> CallSitecoreApi()
{
var token = await HttpContext.GetTokenAsync("access_token");
var client = _httpClientFactory.CreateClient();
client.SetBearerToken(token);
var response = await client.GetStringAsync(Constants.SitecoreApi + "sitecorelayout");
var obj = JsonConvert.DeserializeObject(response);
ViewBag.Json = JsonConvert.SerializeObject(obj, Formatting.Indented);
return View();
[Authorize]
public IActionResult Secure()
{
ViewData["Message"] = "Secure page.";
return View();
}
using System;
using System.IdentityModel.Tokens.Jwt;
using System.Net.Http;
using Clients;
using IdentityModel;
using IdentityModel.Client;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
<ExternalClient>
<ClientId>sitecoremvc</ClientId>
<ClientName>sitecoremvcclient</ClientName>
<ClientSecrets>
<ClientSecret1>abracadabra</ClientSecret1>
</ClientSecrets>
<AccessTokenType>0</AccessTokenType>
<AllowOfflineAccess>true</AllowOfflineAccess>
<AlwaysIncludeUserClaimsInIdToken>false</AlwaysIncludeUserClaimsInIdToken>
<AccessTokenLifetimeInSeconds>3600</AccessTokenLifetimeInSeconds>
@himadric
himadric / Remove-Sitecore9-Instance.ps1
Last active December 20, 2021 19:31
A Powershell script for removing Sitecore 9 instance from local machine
############################################################################################
#This script is created to remove Sitecore 9 instance from local machine.
#This will not uninstall Solr but, it will remove Solr collections.
#The script looks at the Prefix parameter and find out all instances and remove them.
#Change the default values before using the script. Or, pass the values as parameters.
#Usage: .\Remove-Sitecore9-Instance.ps1 -Prefix "xp0"
#Declaimer: This is a destructive script, means, it deletes files, databases etc.
#Use it at your own risk.