Skip to content

Instantly share code, notes, and snippets.

using Sitecore.Owin.Authentication.Configuration;
using Sitecore.Owin.Authentication.Identity;
using Sitecore.Owin.Authentication.Services;
using System;
using Microsoft.AspNet.Identity.Owin;
namespace Foundation.Authentication
{
public class CreateUniqueUser : DefaultExternalUserBuilder
{
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
<sitecore role:require="Standalone or ContentDelivery or ContentManagement">
<!-- Enables Federated Auth -->
<settings>
<setting name="FederatedAuthentication.Enabled">
<patch:attribute name="value">true</patch:attribute>
</setting>
</settings>
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Protocols;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Notifications;
using Microsoft.Owin.Security.OpenIdConnect;
using Owin;
using Sitecore.Owin.Authentication.Configuration;
using Sitecore.Owin.Authentication.Pipelines.IdentityProviders;
@karbyninc
karbyninc / CustomConditions.cs
Last active February 11, 2016 18:10
Sitecore Development Insight - Custom Conditions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Sitecore.Rules;
using Sitecore.Rules.Conditions;
using Sitecore.Data.Items;
using Sitecore.Analytics;
using Karbyn.SC.Core.Extensions;
@karbyninc
karbyninc / UpdatingDatasources.cs
Last active February 11, 2016 17:08
Sitecore Tip: Updating Datasources After Upgrading to Sitecore 7
///
/// Updates the datasource for a rendering from an item path to using the
/// Sitecore ID for the item. The benefit is that this will allow datasources
/// to be able to be freely moved from one area of the content tree to another
/// while enabling the rendering to still function as expected.
///
///The Sitecore.Data.Items.Item to update the datasources for.
public void UpdateDataSourcePathToId(Sitecore.Data.Items.Item itemToProcess)
{
if (null != itemToProcess)
@karbyninc
karbyninc / StrategyPattern.cs
Last active July 4, 2018 10:34
The Strategy Pattern
namespace StrategyPattern.Contracts
{
public interface IDiscountStrategy
{
decimal ApplyDiscount(decimal price);
}
}
@karbyninc
karbyninc / ExceptionHandlers.cs
Last active July 4, 2018 10:38
Handling Errors in Web API Using Exception Filters and Exception Handlers
public override void OnException(HttpActionExecutedContext actionExecutedContext)
@karbyninc
karbyninc / MessageHandlers.cs
Last active February 11, 2016 15:31
Message Handlers in Web API
public class APIKeyHandler : DelegatingHandler
{
private const string REQUEST_HEADER = "X-KARBYN-APIKEY";
protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
bool isValidAPIKey = false;
//Validate that the api key exists, and if so, validate
if (request.Headers.Contains(REQUEST_HEADER))
@karbyninc
karbyninc / TypeConverters.cs
Last active February 11, 2016 15:21
Using TypeConverters in Web API
public class Color
{
public double Red { get; set; }
public double Green { get; set; }
public double Blue { get; set; }
public Color()
{ }
}
public IQueryable<CustomerPurchases> GetPurchases(int customerID)
{
return _purchaseService.GetPurchases(customerID);
}