Skip to content

Instantly share code, notes, and snippets.

View xdumaine's full-sized avatar
🦄

Xander Dumaine xdumaine

🦄
View GitHub Profile
private static OpenIdRelyingParty openId = new OpenIdRelyingParty();
[HttpPost]
public ActionResult OpenId(string identifier)
{
if (!Identifier.IsValid(identifier))
{
ModelState.AddModelError("loginIdentifier",
"The specified login identifier is invalid");
return RedirectToAction("Index");
public ActionResult OpenId()
{
var response = openId.GetResponse();
if (response == null)
{
return RedirectToAction("Index");
}
switch (response.Status)
{
@xdumaine
xdumaine / Id.aspx
Created January 29, 2014 16:07
Adapted from the DotNetOpenAuth > Samples > OpenIdProviderMVC example
<%@ Page Language="C#" AutoEventWireup="true" ContentType="application/xrds+xml" %>
<%@ OutputCache Duration="86400" VaryByParam="none" Location="Any" %><?xml version="1.0" encoding="UTF-8"?>
<%--
This XRDS view is used for both the OP identifier and the user identity pages.
Only a couple of conditional checks are required to share the view, but sharing the view
makes it very easy to ensure that all the Type URIs that this server supports are included
for all XRDS discovery.
--%>
<xrds:XRDS
xmlns:xrds="xri://$xrds"
@xdumaine
xdumaine / OpenIdPartialController.cs
Created January 29, 2014 16:09
Adapted from the DotNetOpenAuth > Samples > OpenIdProviderMVC example
internal static OpenIdProvider OpenIdProvider = new OpenIdProvider();
public ActionResult Id()
{
if (Request.AcceptTypes != null && Request.AcceptTypes.Contains("application/xrds+xml"))
{
ViewData["OPIdentifier"] = true;
}
return View();
}
@xdumaine
xdumaine / OpenIdPartialController.cs
Created January 29, 2014 16:12
Adapted from the DotNetOpenAuth > Samples > OpenIdProviderMVC example
public ActionResult ProcessAuthRequest()
{
if (ProviderEndpoint.PendingRequest == null)
{
return RedirectToAction("About");
}
// Try responding immediately if possible.
ActionResult response = AutoRespondIfPossibleAsync();
if (response != null)
@xdumaine
xdumaine / DocumentationController.cs
Created March 31, 2014 18:41
A controller for serving arbitrary markdown documents from a directory, and having preprocessed keywords for writing.
public class DocumentationController : Controller
{
private const string DefaultDocPage = "Overview";
public ActionResult Index(string id = null)
{
ViewBag.HomeLinkPage = string.IsNullOrEmpty(id) || id == DefaultDocPage ? string.Empty : DefaultDocPage;
if (string.IsNullOrEmpty(ViewBag.HomeLinkPage))
{
id = DefaultDocPage;
}
- (OSStatus)extractIdentity:(CFDataRef)inP12Data :(SecIdentityRef*)identity {
OSStatus securityError = errSecSuccess;
CFStringRef password = CFSTR("MyCertificatePassword");
const void *keys[] = { kSecImportExportPassphrase };
const void *values[] = { password };
CFDictionaryRef options = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL);
CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL);
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
// gets a certificate from local resources
NSString *thePath = [[NSBundle mainBundle] pathForResource:@"MyCertificate" ofType:@"pfx"];
NSData *PKCS12Data = [[NSData alloc] initWithContentsOfFile:thePath];
CFDataRef inPKCS12Data = (CFDataRef)PKCS12Data;
SecIdentityRef identity;
// extract the ideneity from the certificate
[self extractIdentity :inPKCS12Data :&amp;identity];
NSURL *serverURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@", [options objectForKey:@"host"]]];
NSMutableURLRequest *connectionRequest = [NSMutableURLRequest requestWithURL:serverURL
[connectionRequest setHTTPMethod:@"POST"];
[connectionRequest setValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
[connectionRequest setHTTPBody:[[options objectForKey:@"data"] dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection * aConnection = [[NSURLConnection alloc] initWithRequest:connectionRequest delegate:self];
private string username;
public string Username
{
get
{
return username;
}
set
{
username = value;