Skip to content

Instantly share code, notes, and snippets.

View poojarsn's full-sized avatar

santosh poojari poojarsn

View GitHub Profile
@poojarsn
poojarsn / AzureB2c-CodeVerifier
Created January 10, 2024 02:34
Code Verifier and Nonce
#region private methods
private void RememberCodeVerifier(RedirectToIdentityProviderNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> n, string codeVerifier)
{
var properties = new AuthenticationProperties();
properties.Dictionary.Add("cv", codeVerifier);
//if left blank or set to 0, the setting is not used. OOTB default is 15min
if(ConfigurationManager.AppSettings[AzureB2CConstants.Keys.NonceLifetime] != null &&
double.TryParse("30", out double lifetime) && lifetime > 0)
{
@poojarsn
poojarsn / reactjs.tsx
Created December 3, 2023 22:08
Reactjs-Starter
//----1-----
function SomeComponent()
{
return <d><H1>Hellow World</H1><>;
}
export default SomeComponent;
//Concise Way
export default SomeComponent()
{
@poojarsn
poojarsn / Code-Snippet-3
Created July 8, 2016 09:38
Js: Post form in new window
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(function () {
@poojarsn
poojarsn / externallogincallback.cs
Created January 15, 2023 12:27
Sitecore Azure AD B2C User.Identity.IsAuthenticated is false Set AuthenticationManager
/*
Reference
https://blog.baslijten.com/federated-authentication-in-sitecore-error-unsuccessful-login-with-external-provider/
*/
public void SignIn(string returnUrl)
{
// The param returnUrl is configured in Azure B2C Identity Provider.
// The redirect URL is to redirect to externallogincallback method of Sitecore Owin and then load returnUrl Sign-in
var properties = new AuthenticationProperties() { RedirectUri = "https://abc/identity/externallogincallback?ReturnUrl=/sign-in" };
@poojarsn
poojarsn / Google API Distance View.htm
Last active January 7, 2023 07:03
Calculate distance between two location using Google Map API
<div>
<h2>
Orign Location
</h2>
</div>
<div id="locationField">
<input id="originautocomplete" placeholder="Enter your address" onFocus="geolocate()" type="text"></input>
</div>
<div>
//Azure AD B2C Owin Context is null , once the token is acquired by authorization code flow
//Set Authentication Manager profile
var authenticated = HttpContext.GetOwinContext().Authentication.AuthenticateAsync("ExternalCookie");
// Send Access Token bearer to api to get logged user details
var loggedInUser = AuthenticationManager.BuildVirtualUser(string.Format(@"{0}\{1}", "external", "User-ID"), true);
loggedInUser.RuntimeSettings.AddedRoles.Add(authenticated.Result.Identity.Claims.First().Value);
loggedInUser.Profile.FullName = string.Format("{0} {1}", authenticated.Result.Identity.Name, authenticated.Result.Identity.Claims.Last().Value);
loggedInUser.Profile.Save();
@poojarsn
poojarsn / swagger.cs
Created July 16, 2022 11:19
Get all controller action mvc asp.net
Assembly asm = Assembly.GetAssembly(typeof(MyWebDll.MvcApplication));
var controlleractionlist = asm.GetTypes()
.Where(type=> typeof(System.Web.Mvc.Controller).IsAssignableFrom(type))
.SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public))
.Where(m => !m.GetCustomAttributes(typeof( System.Runtime.CompilerServices.CompilerGeneratedAttribute), true).Any())
.Select(x => new {Controller = x.DeclaringType.Name, Action = x.Name, ReturnType = x.ReturnType.Name, Attributes = String.Join(",", x.GetCustomAttributes().Select(a => a.GetType().Name.Replace("Attribute",""))) })
.OrderBy(x=>x.Controller).ThenBy(x => x.Action).ToList();
@poojarsn
poojarsn / Redis Cache Get Set
Created October 14, 2021 09:54
Redis Cache Get Set PrivateSetterContractResolver
public class SessionService : ISessionService
{
private readonly ICryptoService _cryptoService;
private readonly string _encryptionKey = ConfigurationManager.AppSettings[AppSettingKeys.Common.SessionEncryptionKey];
public SessionService(ICryptoService cryptoService)
{
_cryptoService = cryptoService;
}
@poojarsn
poojarsn / Oops.cs
Created August 16, 2021 23:02
Two interfaces with same method
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
I1 ia = new C();
ia.Method1();
@poojarsn
poojarsn / CustomSitecorePipeline.cs
Created March 7, 2018 03:42
Sitecore Pipeline HttpBeginRequest - Processor HttpRequestProcessor : Intercept requests before page get processed completely.
using Sitecore;
using Sitecore.Pipelines.HttpRequest;
using System.Web.Security;
namespace MyProject.Customm.Pipelines.HttpRequest
{
    /// <summary>
    ///     The pipeline processor intercept site setting EnabledMaintenance flag before request get processed.
    /// </summary>