Auth custom using IAuthenticationFilter and AuthorizeAttribute

public class AuthenticationServiceAttribute : IAuthenticationFilter { public AuthenticationServiceAttribute() { } public async Task AuthenticateAsync(HttpAuthenticationContext actionContext, CancellationToken cancellationToken) { if (actionContext.Request.Headers.Authorization != null) { var cacheResponse = _memoryProvider.Get<MYCLASS>(“key”); if (cacheResponse != null) { await Validate(cacheResponse.access_token, actionContext.Request.Headers.Authorization.Parameter.ToString(), actionContext); return; } else { AuthTokenEntity serviceToken = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri(ConfigurationManager.AppSettings[“AuthBaseAddress”]);… Read More Auth custom using IAuthenticationFilter and AuthorizeAttribute

caching – memory

public interface ICache { /// <summary> /// Retrieve cached item /// </summary> /// <typeparam name=”T”>Type of cached item</typeparam> /// <param name=”key”>Name of cached item</param> /// <returns>Cached value. Default(T) if item doesn’t exist.</returns> T Get<T>(string key); /// <summary> /// Insert value into the cache using appropriate name/value pairs /// Use predefined cache duration with absolute expiration… Read More caching – memory

add custom swagger header

Yes you can do it via inheriting from IOperationFilter You can find the answer on github here: AddRequiredHeaderParameter public class AddRequiredHeaderParameter : IOperationFilter { public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { if (operation.parameters == null) operation.parameters = new List<Parameter>(); operation.parameters.Add(new Parameter { name = “X-User-Token”, @in = “header”, type = “string”, required = false });… Read More add custom swagger header

Twitter API v1.1 with OAuth

Introduction The OAuth protocol enables websites or applications (Consumers) to access Protected Resources from a web service (Service Provider) via an API, without requiring Users to disclose their Service Provider credentials to the Consumers. More generally, OAuth creates a freely-implementable and generic methodology for API authentication. OAuth aims to unify the experience and implementation of… Read More Twitter API v1.1 with OAuth

Generate sql script using c# code

class Program { static void Main(string[] args) { string dbConnectionString = “Server=./sqlexpress;Database=mydata;User ID=sa;Password=test@111;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;”; string databaseName = “mydata”; ScriptDatabase(dbConnectionString, databaseName); } public static string ScriptDatabase(string dbConnectionString, string databaseName) { SqlConnection conn = new SqlConnection(dbConnectionString); ServerConnection serverConn = new ServerConnection(conn); var server = new Server(serverConn); var database = server.Databases[databaseName]; var scripter = new Scripter(server); /* With… Read More Generate sql script using c# code

execute sql script c# code

public void Execute(string sqlfilePath) { string dbConnectionString = “”; try { using (StreamReader file = new StreamReader(filePath)) using (SqlConnection conn = new SqlConnection(dbConnectionString)) { StringBuilder sql = new StringBuilder(); string line; while ((line = file.ReadLine()) != null) { // replace GO with semi-colon if (line == “GO”) sql.Append(“;”); // remove inline comments else if (line.IndexOf(“–“)… Read More execute sql script c# code

create user to azure ad   services platforms author active-directory dotnet dstrockis Build a multi-tenant SaaS web application using Azure AD & OpenID Connect This sample shows how to build a multi-tenant .Net MVC web application that uses OpenID Connect to sign up and sign in users from any Azure Active Directory tenant, using the ASP.Net OpenID Connect OWIN… Read More create user to azure ad