Skip to content

Instantly share code, notes, and snippets.

View vbookie's full-sized avatar

Viktor Bukurov vbookie

View GitHub Profile
private Task SecurityTokenValidatedInternal(SecurityTokenValidatedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> notification)
{
var identity = notification.AuthenticationTicket.Identity;
// Instead of getting the email claim, get another claim to identify the user and generate a unique email
var externalUserUniqueClaim = identity.FindFirst("someuniqueclaim");
if (externalUserUniqueClaim != null)
{
var userEmail = externalUserUniqueClaim.Value + "@somedomain.test";
using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Protocols;
using Microsoft.Owin;
using Microsoft.Owin.Security.Notifications;
using Microsoft.Owin.Security.OpenIdConnect;
using Owin;
using Telerik.Sitefinity.Authentication;
@vbookie
vbookie / CustomExternalAuthenticationProvider.cs
Created February 23, 2017 07:33
Custom external authentication provider
public class CustomGoogleAuthenticationProvider : SitefinityGoogleAuthenticationProvider
{
public override Task Authenticated(GoogleOAuth2AuthenticatedContext context)
{
var isIdentityValid = YourCustomCheck();
if (!isIdentityValid)
{
context.Identity = null;
return Task.FromResult(0);
}