Skip to content

Instantly share code, notes, and snippets.

@johnkors
Created February 3, 2017 16:22
Show Gist options
  • Save johnkors/e1ff331796db337dba0ef8591253f456 to your computer and use it in GitHub Desktop.
Save johnkors/e1ff331796db337dba0ef8591253f456 to your computer and use it in GitHub Desktop.
/core/discourse
// Redirected from Discourse
[Route("core/discourse")]
[HttpGet]
public async Task<ActionResult> Index(string sso, string sig)
{
if (!IsValid(sso, sig))
{
throw new SecurityException("sso sig not valid");
}
var idsrvClaimsIdentity = await Request.GetOwinContext().Environment.GetIdentityServerFullLoginAsync();
var isAuthenticated = idsrvClaimsIdentity != null;
if (isAuthenticated)
{
// User authenticated, getting user, generating sso and redirecting back to Discourse
var user = Users.GetUserBySub(idsrvClaimsIdentity.FindFirst(c => c.Type == "sub").Value);
var redirectUrl = CreateDiscourseRedirectUrl(user, sso);
return new RedirectResult(redirectUrl);
}
// Not authenticated, returning login page
TempData["sso"] = sso;
return View();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment