All Projects → jitbit → Aspnetsaml

jitbit / Aspnetsaml

Licence: apache-2.0
Very simple SAML 2.0 consumer module for ASP.NET/C#

Projects that are alternatives of or similar to Aspnetsaml

AspNetCore-Dynamic-Permission
Dynamic Permission Samples in ASP.NET Core and ASP.NET MVC 5.
Stars: ✭ 19 (-89.27%)
Mutual labels:  asp-net, asp-net-mvc
steamstatus
A quick and dirty POC website to view the status of Steam CM servers. Precursor to steamstat.us
Stars: ✭ 67 (-62.15%)
Mutual labels:  asp-net, asp-net-mvc
Cake-Shop
A sample Cake Shop Website built with ASP.NET Core (Multi-Page Application)
Stars: ✭ 44 (-75.14%)
Mutual labels:  asp-net, asp-net-mvc
Uintra
A flexible and lightweight Umbraco based framework, for making an Intranet, Extranet or social platform based on known conventions.
Stars: ✭ 43 (-75.71%)
Mutual labels:  asp-net, asp-net-mvc
Reinforced.typings
Converts C# classes to TypeScript interfaces (and many more) within project build. 0-dependency, minimal, gluten-free
Stars: ✭ 341 (+92.66%)
Mutual labels:  asp-net, asp-net-mvc
elmah.io
ELMAH error logger for sending errors to elmah.io.
Stars: ✭ 31 (-82.49%)
Mutual labels:  asp-net, asp-net-mvc
RazorHtmlMinifier.Mvc5
↘️ Trivial compile-time Razor HTML Minifier for ASP.NET MVC 5.
Stars: ✭ 31 (-82.49%)
Mutual labels:  asp-net, asp-net-mvc
BlipBinding
ASP.NET MVC case study solution for PluralSight Guides. Demonstrates how to use default MVC model binding with hierarchical form data.
Stars: ✭ 29 (-83.62%)
Mutual labels:  asp-net, asp-net-mvc
React Aspnet Boilerplate
A starting point for building isomorphic React applications with ASP.NET Core, leveraging existing techniques.
Stars: ✭ 285 (+61.02%)
Mutual labels:  asp-net, asp-net-mvc
Ad-Hoc-Report-Builder-.net-mvc
Open Source Reporting tool for .NET6/.NET Core/.NET Framework that you can embed in your application and generate dashboards and ad hoc reports
Stars: ✭ 43 (-75.71%)
Mutual labels:  asp-net, asp-net-mvc
PersianDataAnnotations
PersianDataAnnotations is ASP.NET Core MVC & ASP.NET MVC Custom Localization DataAnnotations (Localized MVC Errors) for Persian(Farsi) language - فارسی سازی خطاهای اعتبارسنجی توکار ام.وی.سی. و کور.ام.وی.سی. برای نمایش اعتبار سنجی سمت کلاینت
Stars: ✭ 38 (-78.53%)
Mutual labels:  asp-net, asp-net-mvc
Xclcms
XCLCMS is a lightweight CMS (content management system) background management system, Developed using asp.net MVC, it provides a simple and easy-to-use web API interface and supports multiple applications for a single merchant.
Stars: ✭ 107 (-39.55%)
Mutual labels:  asp-net, asp-net-mvc
DNZ.SEOChecker
SEO Checker and Recommander Plugin (like wordpress Yoast) for ASP.NET Core.
Stars: ✭ 18 (-89.83%)
Mutual labels:  asp-net, asp-net-mvc
TraceHub
Centralized and distributed logging for Web applications and services, extending System.Diagnostics and Essential.Diagnostics, providing structured tracing and logging withou needing to change 1 line of your application codes
Stars: ✭ 22 (-87.57%)
Mutual labels:  asp-net, asp-net-mvc
ByteScout-SDK-SourceCode
ALL source code samples for ByteScout SDKs and Web API API products.
Stars: ✭ 24 (-86.44%)
Mutual labels:  asp-net, asp-net-mvc
Awesome-Nuget-Packages
📦 A collection of awesome and top .NET packages sorted by most popular needs.
Stars: ✭ 87 (-50.85%)
Mutual labels:  asp-net, asp-net-mvc
MVC5Course
【ASP.NET MVC 5 開發實戰:從入門到進階】實作練習專案
Stars: ✭ 19 (-89.27%)
Mutual labels:  asp-net, asp-net-mvc
Csla
A home for your business logic in any .NET application.
Stars: ✭ 865 (+388.7%)
Mutual labels:  asp-net, asp-net-mvc
Recaptcha Net
reCAPTCHA for .NET library lets you easily use Google's reCAPTCHA in an ASP.NET Web Forms / MVC / ASP.NET Core application.
Stars: ✭ 116 (-34.46%)
Mutual labels:  asp-net, asp-net-mvc
Lite Idp
Lightweight SAML Identity Provider
Stars: ✭ 130 (-26.55%)
Mutual labels:  saml

AspNetSaml

Very simple SAML 2.0 "consumer" implementation in C#.

It's a SAML client library, not a SAML server, allows adding SAML single-sign-on to your ASP.NET app, but not to provide auth services to other apps.

Installation

Consists of one short C# file you can throw into your project (or install via nuget) and start using it.

Usage

How SAML works?

SAML workflow has 2 steps:

  1. User is redirected to the SAML provider (where he authenticates)
  2. User is redirected back to your app, where you validate the payload

Here's how you do it (this example is for ASP.NET MVC:

1. Redirecting the user to the saml provider:

//this example is an ASP.NET MVC action method
public ActionResult Login()
{
	//TODO: specify the SAML provider url here, aka "Endpoint"
	var samlEndpoint = "http://saml-provider-that-we-use.com/login/";

	var request = new AuthRequest(
		"http://www.myapp.com", //TODO: put your app's "entity ID" here
		"http://www.myapp.com/SamlConsume" //TODO: put Assertion Consumer URL (where the provider should redirect users after authenticating)
		);

	//redirect the user to the SAML provider
	return Redirect(request.GetRedirectUrl(samlEndpoint));
}

2. User has been redirected back

User is sent back to your app - you need to validate the SAML response ("assertion") that you recieved via POST.

Here's an example of how you do it in ASP.NET MVC

//ASP.NET MVC action method... But you can easily modify the code for Web-forms etc.
public ActionResult SamlConsume()
{
	// 1. TODO: specify the certificate that your SAML provider gave you
	string samlCertificate = @"-----BEGIN CERTIFICATE-----
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH123543==
-----END CERTIFICATE-----";

	// 2. Let's read the data - SAML providers usually POST it into the "SAMLResponse" var
	Saml.Response samlResponse = new Response(samlCertificate, Request.Form["SAMLResponse"]);

	// 3. We're done!
	if (samlResponse.IsValid())
		username = samlResponse.GetNameID();
}

Reading more attributes from the provider

SAML providers usually send more data with their response: username, first/last names etc. Here's how to get it:

if (samlResponse.IsValid())
{
	//WOOHOO!!! user is logged in

	//Some more optional stuff for you
	//let's extract username/firstname etc
	string username, email, firstname, lastname;
	try
	{
		username = samlResponse.GetNameID();
		email = samlResponse.GetEmail();
		firstname = samlResponse.GetFirstName();
		lastname = samlResponse.GetLastName();
	}
	catch(Exception ex)
	{
		//insert error handling code
		//no, really, please do
		return null;
	}

	//user has been authenticated, put your code here, like set a cookie or something...
	//or call FormsAuthentication.SetAuthCookie() or something
}

Dependencies

Depending on your .NET version, your Project should reference System.Security for .NET Framework and System.Security.Cryptography.Xml for .NET Core.

(NEW!) Nuget

I've published this to Nuget.

Install-Package AspNetSaml

This will simply add the cs-file to the root of your project.

A version of this library has been used for years in production in our helpdesk app.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].