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 / 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" };
//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 / Leaq.c
Created July 17, 2020 04:15
Leaq convertible c programming
#include <stdio.h>
short scale3(short x, short y, short z);
int main()
{
printf("Hello World");
short temp;
temp=scale3(2,3,4);
printf("%u",temp);
return 0;
}
@poojarsn
poojarsn / RedisCacheProvider.cs
Last active December 18, 2020 05:36
Azure Redis cache asp.net provider
public interface ICacheProvider
{
T Get<T>(string key, Func<T> fetch) where T : class;
IEnumerable<T> GetAll<T>(IReadOnlyCollection<string> keys, Func<IEnumerable<T>> fetch, Func<T, string, string> keyGen, string keyPrefix) where T : class;
void Clear(string key);
}
//Encryt and decrypt
//Logging service
//Key for different env same shared redis cache
@poojarsn
poojarsn / CalculateBlocksUsingJs.js
Created May 7, 2020 04:30
Calculate blocks of wood cost using javascript
<!DOCTYPE html>
<html>
<head><title>Study Hard for the Test</title></head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;