Skip to content

Instantly share code, notes, and snippets.

View johnkors's full-sized avatar

John Korsnes johnkors

  • Blank
  • Oslo
  • 10:38 (UTC +02:00)
View GitHub Profile
@johnkors
johnkors / DiscourseController.cs
Last active February 3, 2017 15:09
/core/discourse
[Route("core/discourse")]
[HttpGet]
public async Task<ActionResult> Index(string sso, string sig)
{
if (string.IsNullOrEmpty(sso) || string.IsNullOrEmpty(sig))
{
throw new ArgumentException("Missing input parameters");
}
if (!IsValid(sso, sig))
@johnkors
johnkors / Validator.cs
Last active February 3, 2017 15:11
Validation of Discourse SSO payload
private static bool IsValid(string encodedPayload, string signature)
{
return Hash(DISCOURSE_SECRET, encodedPayload) == signature;
}
private static string Hash(string secret, string encodedPayload)
{
var hasher = new HMACSHA256(Encoding.UTF8.GetBytes(secret));
var hash = hasher.ComputeHash(Encoding.UTF8.GetBytes(encodedPayload));
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
@johnkors
johnkors / GoogleMailSender.cs
Created January 31, 2017 08:19
Sample of a gmail email-sender
using System;
using System.Net;
using System.Net.Mail;
public class Email
{
public string From;
public string To;
public string Subject;
public string Text;
@johnkors
johnkors / Chat extract from Slack
Created December 8, 2016 12:37
Why use NETStandard.Library as a dependency instead of explicitly defining what you use from the BCL (NETStandard.Library)
https://aspnetcore.slack.com/archives/dotnet-core/p1481195518000050
johnkors [12:11 PM]
what do I, as a library author, gain by depending on `NETStandard.Library` instead of explicitly _just_ the nugets I need? (edited)
johnkors [12:26 PM]
- Some do : https://www.nuget.org/packages/xunit.abstractions/ @bradwilson
- Others don't : https://www.nuget.org/packages/Newtonsoft.Json/9.0.1 , @jamesnk
Wonder what's "better"; or why one would prefer one over the other. (edited)
@johnkors
johnkors / user-profile.cmd
Created July 8, 2016 11:16
cmder user-profile.cmd (ssh-agent, updated path to git)
echo "*** Welcome, John! ***"
set "GIT_INSTALL_ROOT=C:\tools\msysgit"
:: Add git to the path
if defined GIT_INSTALL_ROOT (
set "PATH=%GIT_INSTALL_ROOT%\bin;%GIT_INSTALL_ROOT%\usr\bin;%GIT_INSTALL_ROOT%\usr\share\vim\vim74;%PATH%"
:: define SVN_SSH so we can use git svn with ssh svn repositories
if not defined SVN_SSH set "SVN_SSH=%GIT_INSTALL_ROOT:\=\\%\\bin\\ssh.exe"
)
@johnkors
johnkors / GetToken.ps1
Last active June 12, 2024 08:34
Fetch an accesstoken from IdentityServer3 using PowerShell 3
<#
.SYNOPSIS
Fetches an access token using the IdentityServer3 token endpoint
.DESCRIPTION
Modify the parameters so it matches your IdentityServer3 instance.
.NOTES
File Name : GetToken.ps1
Author : John Korsnes (@johnkors, johnkors)
Prerequisite : PowerShell V3
.LINK
@johnkors
johnkors / Startup.cs
Last active May 31, 2019 01:22
Do Not Redirect To IdentityServer On Ajax 401
public void Configuration(IAppBuilder app)
{
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Notifications = new OpenIdConnectAuthenticationNotifications
{
RedirectToIdentityProvider = RedirectToIdProvider
}
});
}
@johnkors
johnkors / CustomHandleErrorAttribute.cs
Created January 15, 2016 14:21 — forked from lkaczanowski/CustomHandleErrorAttribute.cs
Custom ASP.NET MVC handle error attribute. Handles and logs all errors.
public class CustomHandleErrorAttribute : HandleErrorAttribute
{
private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public override void OnException(ExceptionContext filterContext)
{
_log.Error("Internal server error occurred while handling web request.", filterContext.Exception);
if (!filterContext.HttpContext.IsCustomErrorEnabled)
{
return;
@johnkors
johnkors / gist:c6f05a665c980140402f
Created May 4, 2015 13:23
Autofac exceptions idsrv
at System.Threading.CancellationToken.ThrowOperationCanceledException()
at System.Web.Http.Owin.HttpMessageHandlerAdapter.<BufferResponseContentAsync>d__13.MoveNext() in c:\ballen\github\thinktecture\IdSrv3\Thinktecture.IdentityServer3\source\Core\Services\Default\DefaultConsentService.cs:line 0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Owin.HttpMessageHandlerAdapter.<InvokeCore>d__0.MoveNext() in c:\ballen\github\thinktecture\IdSrv3\Thinktecture.IdentityServer3\source\Core\Services\Default\DefaultConsentService.cs:line 0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.T