ShibbolethLogin 1.0.0
dotnet add package ShibbolethLogin --version 1.0.0
NuGet\Install-Package ShibbolethLogin -Version 1.0.0
<PackageReference Include="ShibbolethLogin" Version="1.0.0" />
<PackageVersion Include="ShibbolethLogin" Version="1.0.0" />
<PackageReference Include="ShibbolethLogin" />
paket add ShibbolethLogin --version 1.0.0
#r "nuget: ShibbolethLogin, 1.0.0"
#:package ShibbolethLogin@1.0.0
#addin nuget:?package=ShibbolethLogin&version=1.0.0
#tool nuget:?package=ShibbolethLogin&version=1.0.0
ShibbolethLogin
Shibboleth login library which can be used for single sign-on. It allows also use Active Directory.
Configuration
After adding this library to your project, it is neccesary to make settings in your Startup.cs file.
There is example of ConfigureServices method.
public void ConfigureServices(IServiceCollection services)
{
var shibbolethClaims = new List<ClaimValuePair>() { new ClaimValuePair(ClaimTypes.GivenName, "cn") };
var adClaims = new List<ClaimValuePair>() { new ClaimValuePair(ClaimTypes.Email, "mail") };
services.AddSingleton<IClaimsConfig, ClaimsConfig>();
services.AddSingleton<IRoleResolver>(new JsonConfigRoleResolver(Path.Combine(WebHostEnvironment.WebRootPath, "roles.json")));
services.AddSingleton<IADConfig>(new ADConfig(Configuration["AD:Server"], Configuration["AD:Container"], Configuration["AD:User"], Configuration["AD:Password"], adClaims));
services.AddSingleton<IShibbolethConfig>(new ShibbolethConfig(Configuration["Shibboleth:LoginUrl"], Configuration["Shibboleth:LogoutUrl"], Configuration["Shibboleth:AfterLoginPath"], shibbolethClaims, true, true, Configuration["Shibboleth:Testing"] == "true"));
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.Cookie.Name = "ShibbolethLogin";
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(30);
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/LogOut";
});
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
options.Cookie.HttpOnly = true;
});
services.AddControllersWithViews();
}
You can specify which informations from Shibboleth or AD will be in claims. This line:
var shibbolethClaims = new List<ClaimValuePair>() { new ClaimValuePair(ClaimTypes.GivenName, "cn") };
Defines that claim name will be GivenName and "cn" will be value from Shibboleth headers. This list of claims you can pass by parameter in new ShibboletConfig service.
If you add this line of code services.AddSingleton<IClaimsConfig, ClaimsConfig>();
you have to create ClaimsConfig file which inherites from interface IClaimsConfig and implement method EditClaims(ClaimsIdentity claims, HttpContext context)
where you can add your custom claims or do whatever you want.
If you want to use roles from file, you can add line services.AddSingleton<IRoleResolver>(new JsonConfigRoleResolver(Path.Combine(WebHostEnvironment.WebRootPath, "roles.json")));
. The roles.json file structure is as follows
[
{
"Name": "superadmin",
"Users": ["user123", "user234"],
"ADGroups": [ ],
"ChildRoles": [ ]
},
{
"Name": "employee",
"Users": [],
"ADGroups": [ "zamestnanec" ],
"ChildRoles": [ ]
},
{
"Name": "student",
"Users": [ ],
"ADGroups": [ "student" ],
"ChildRoles": [ ]
}
]
If you will be use Active Directory then it get user roles from AD by ADGroups array. So if you want to user Active Directory, you have to register IADConfig service.
Always it is neccesary to register IShibbolethConfig service! There you will specify login url, logout url, claims, if you will be using Active Directory etc.
The next step is add the following code:
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.Cookie.Name = "ShibbolethLogin";
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(30);
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/LogOut";
});
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
options.Cookie.HttpOnly = true;
});
There you can set your Cookie name and expire time. LoginPath and LogoutPath must be always as in this example!
The last important step is add this three lines to Configure method.
app.UseAuthentication();
app.UseAuthorization();
app.UseSession();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.AspNetCore.Authentication.Cookies (>= 2.2.0)
- Microsoft.AspNetCore.Mvc (>= 2.2.0)
- System.DirectoryServices (>= 4.7.0)
- System.DirectoryServices.AccountManagement (>= 4.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0 | 614 | 6/23/2020 |