refactorisation : separation du code serveur d'authentification

vnext
Paul Schneider 7 years ago
parent 815371bfa3
commit d287eabb48
57 changed files with 5452 additions and 108 deletions

@ -3,7 +3,6 @@ using Microsoft.AspNet.Builder;
using Microsoft.AspNet.DataProtection; using Microsoft.AspNet.DataProtection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.WebEncoders; using Microsoft.Extensions.WebEncoders;
using Yavsc.Auth;
namespace OAuth.AspNet.AuthServer namespace OAuth.AspNet.AuthServer
{ {

@ -0,0 +1,41 @@
{
"version": "1.0.5-*",
"description": "OAuth AspNet Server",
"authors": [
"Paul Schneider <paul@pschneider.fr>"
],
"packOptions": {
"repository": {
"type": "git",
"url": "https://github.com/pazof/yavsc"
},
"licenseUrl": "https://github.com/pazof/yavsc/blob/vnext/LICENSE",
"requireLicenseAcceptance": true,
"owners": [
"Paul Schneider <paul@pschneider.fr>"
],
"summary": "Yet another very small company",
"projectUrl": "http://yavsc.pschneider.fr",
"tags": [
"Authorization server",
"OAuth",
"Web API"
]
},
"tooling": {
"defaultNamespace": "Yavsc"
},
"dependencies": {
"Newtonsoft.Json": "9.0.1",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-*",
"OAuth.AspNet.Token": {
"type": "build",
"target": "project"
}
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {}
}
}
}

File diff suppressed because it is too large Load Diff

@ -4,37 +4,35 @@
using System; using System;
using System.IO; using System.IO;
using Microsoft.AspNet.DataProtection; using Microsoft.AspNet.DataProtection;
namespace Yavsc.Auth
{
public class MonoDataProtectionProvider : IDataProtectionProvider public class MonoDataProtectionProvider : IDataProtectionProvider
{ {
private readonly string appName; private readonly string appName;
public MonoDataProtectionProvider() public MonoDataProtectionProvider()
: this(Guid.NewGuid().ToString()) : this(Guid.NewGuid().ToString())
{ } { }
public MonoDataProtectionProvider(DirectoryInfo dataProtectionDirInfo) public MonoDataProtectionProvider(DirectoryInfo dataProtectionDirInfo)
: this(Guid.NewGuid().ToString()) : this(Guid.NewGuid().ToString())
{ {
} }
public MonoDataProtectionProvider(string appName) public MonoDataProtectionProvider(string appName)
{ {
if (appName == null) { throw new ArgumentNullException("appName"); } if (appName == null) { throw new ArgumentNullException("appName"); }
this.appName = appName; this.appName = appName;
} }
public IDataProtector Create(params string[] purposes) public IDataProtector Create(params string[] purposes)
{ {
if (purposes == null) { throw new ArgumentNullException("purposes"); } if (purposes == null) { throw new ArgumentNullException("profile"); }
return new MonoDataProtector(appName, purposes); return new MonoDataProtector(appName, purposes);
} }
public IDataProtector CreateProtector(string purpose) public IDataProtector CreateProtector(string purpose)
{ {
return Create(new string[] {purpose}); return Create(new string[] { purpose });
}
} }
} }

@ -0,0 +1,83 @@
//
// MonoDataProtector.cs
//
// Author:
// Paul Schneider <paul@pschneider.fr>
//
// Copyright (c) 2016 GNU GPL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Security.Cryptography;
using System.IO;
using Microsoft.AspNet.DataProtection;
using System.Linq;
public class MonoDataProtector : IDataProtector
{
private const string PRIMARY_PURPOSE = "IDataProtector";
private readonly string appName;
private readonly DataProtectionScope dataProtectionScope;
private readonly string[] purposes;
public MonoDataProtector(string appName, string[] purposes)
{
if (appName == null) { throw new ArgumentNullException("appName"); }
if (purposes == null) { throw new ArgumentNullException("purposes"); }
this.appName = appName;
this.purposes = purposes;
this.dataProtectionScope = DataProtectionScope.CurrentUser;
}
public IDataProtector CreateProtector(string purpose)
{
if (purposes.Contains(purpose))
return new MonoDataProtector(appName, new string[] { purpose });
return new MonoDataProtector(appName, new string[] { });
}
public byte[] Protect(byte[] userData)
{
return ProtectedData.Protect(userData, this.GetEntropy(), dataProtectionScope);
}
public byte[] Unprotect(byte[] protectedData)
{
return ProtectedData.Unprotect(protectedData, this.GetEntropy(), dataProtectionScope);
}
private byte[] GetEntropy()
{
using (SHA256 sha256 = SHA256.Create())
{
using (MemoryStream memoryStream = new MemoryStream())
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, sha256, CryptoStreamMode.Write))
using (StreamWriter writer = new StreamWriter(cryptoStream))
{
writer.Write(this.appName);
writer.Write(PRIMARY_PURPOSE);
foreach (string purpose in this.purposes)
{
writer.Write(purpose);
}
}
return sha256.Hash;
}
}
}

@ -4,8 +4,6 @@ using System;
using System.IdentityModel.Tokens; using System.IdentityModel.Tokens;
using System.Security.Claims; using System.Security.Claims;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Yavsc.Auth;
using Yavsc;
namespace OAuth.AspNet.Tokens namespace OAuth.AspNet.Tokens
{ {
@ -20,8 +18,8 @@ namespace OAuth.AspNet.Tokens
{ {
if (dataProtectionProvider == null) if (dataProtectionProvider == null)
{ {
dataProtectionProvider = new MonoDataProtectionProvider(Constants.ApplicationName) dataProtectionProvider = new MonoDataProtectionProvider(System.AppDomain.CurrentDomain.FriendlyName)
.CreateProtector(Constants.KeyProtectorPurpose); .CreateProtector("profile");
} }
_ticketDataFormat = new TicketDataFormat(dataProtectionProvider.CreateProtector("Access_Token", "v1")); _ticketDataFormat = new TicketDataFormat(dataProtectionProvider.CreateProtector("Access_Token", "v1"));
} }

@ -0,0 +1,38 @@
{
"version": "1.0.5-*",
"description": "OAuth AspNet Token",
"authors": [
"Paul Schneider <paul@pschneider.fr>"
],
"packOptions": {
"repository": {
"type": "git",
"url": "https://github.com/pazof/yavsc"
},
"licenseUrl": "https://github.com/pazof/yavsc/blob/vnext/LICENSE",
"requireLicenseAcceptance": true,
"owners": [
"Paul Schneider <paul@pschneider.fr>"
],
"summary": "Yet another very small company",
"projectUrl": "http://yavsc.pschneider.fr",
"tags": [
"Authorization server",
"OAuth",
"Web API"
]
},
"tooling": {
"defaultNamespace": "Yavsc"
},
"dependencies": {
"Newtonsoft.Json": "9.0.1",
"Microsoft.AspNet.Authentication.JwtBearer": "1.0.0-rc1-final",
"Microsoft.AspNet.DataProtection": "1.0.0-rc1-final"
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {}
}
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,23 @@
<?xml version="1.0"?>
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Yavsc.Server</id>
<title>Yavsc: Server common library</title>
<version>$version$</version>
<authors>Paul Schneider</authors>
<owners>Paul Schneider</owners>
<licenseUrl>https://github.com/pazof/yavsc/blob/vnext/Yavsc/License.md</licenseUrl>
<projectUrl>https://github.com/pazof/yavsc/README.md</projectUrl>
<iconUrl>https://github.com/pazof/yavsc/blob/vnext/Yavsc/wwwroot/images/yavsc.png</iconUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>
Some common server side bytes
</description>
<summary>
</summary>
<tags>yavsc</tags>
</metadata>
<files>
<file src="bin/$config$/net451/Yavsc.Server.dll" target="lib/portable-net45+win8+wp8+wpa81+Xamarin.Mac+MonoAndroid10+MonoTouch10+Xamarin.iOS10" />
</files>
</package>

@ -108,6 +108,7 @@
"fx/System.ComponentModel.DataAnnotations >= 4.0.0", "fx/System.ComponentModel.DataAnnotations >= 4.0.0",
"fx/System.Json >= 4.0.0", "fx/System.Json >= 4.0.0",
"fx/System.Net >= 4.0.0", "fx/System.Net >= 4.0.0",
"fx/System.Net.Http >= 4.0.0",
"fx/System.Xml >= 4.0.0", "fx/System.Xml >= 4.0.0",
"fx/System >= 4.0.0" "fx/System >= 4.0.0"
] ]

@ -1,87 +0,0 @@
//
// MonoDataProtector.cs
//
// Author:
// Paul Schneider <paul@pschneider.fr>
//
// Copyright (c) 2016 GNU GPL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Security.Cryptography;
using System.IO;
using Microsoft.AspNet.DataProtection;
using System.Linq;
namespace Yavsc.Auth
{
public class MonoDataProtector : IDataProtector
{
private const string PRIMARY_PURPOSE = "IDataProtector";
private readonly string appName;
private readonly DataProtectionScope dataProtectionScope;
private readonly string[] purposes;
public MonoDataProtector(string appName, string[] purposes)
{
if (appName == null) { throw new ArgumentNullException("appName"); }
if (purposes == null) { throw new ArgumentNullException("purposes"); }
this.appName = appName;
this.purposes = purposes;
this.dataProtectionScope = DataProtectionScope.CurrentUser;
}
public IDataProtector CreateProtector(string purpose)
{
if (purposes.Contains(purpose))
return new MonoDataProtector(appName,new string[] {purpose});
return new MonoDataProtector(appName,new string[] {});
}
public byte[] Protect(byte[] userData)
{
return ProtectedData.Protect(userData, this.GetEntropy(), dataProtectionScope);
}
public byte[] Unprotect(byte[] protectedData)
{
return ProtectedData.Unprotect(protectedData, this.GetEntropy(), dataProtectionScope);
}
private byte[] GetEntropy()
{
using (SHA256 sha256 = SHA256.Create())
{
using (MemoryStream memoryStream = new MemoryStream())
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, sha256, CryptoStreamMode.Write))
using (StreamWriter writer = new StreamWriter(cryptoStream))
{
writer.Write(this.appName);
writer.Write(PRIMARY_PURPOSE);
foreach (string purpose in this.purposes)
{
writer.Write(purpose);
}
}
return sha256.Hash;
}
}
}
}

@ -25,7 +25,6 @@ namespace Yavsc
BlogModeratorGroupName = "Moderator", BlogModeratorGroupName = "Moderator",
FrontOfficeGroupName = "FrontOffice", FrontOfficeGroupName = "FrontOffice",
GCMNotificationUrl = "https://gcm-http.googleapis.com/gcm/send", GCMNotificationUrl = "https://gcm-http.googleapis.com/gcm/send",
KeyProtectorPurpose = "OAuth.AspNet.AuthServer",
UserFilesPath = "/UserFiles", UserFilesPath = "/UserFiles",
AvatarsPath = "/avatars", AvatarsPath = "/avatars",
DefaultAvatar = "/images/Users/icon_user.png", DefaultAvatar = "/images/Users/icon_user.png",

@ -130,10 +130,16 @@ namespace Yavsc.Controllers
return View(); return View();
} }
public IActionResult VideoChat() public IActionResult VideoChat()
{ {
return View(); return View();
} }
} public IActionResult Audio()
{
return View();
}
}
} }

@ -98,6 +98,7 @@ namespace Yavsc
app.UseWhen(context => context.Request.Path.StartsWithSegments("/api"), app.UseWhen(context => context.Request.Path.StartsWithSegments("/api"),
branch => branch =>
{ {
branch.UseJwtBearerAuthentication( branch.UseJwtBearerAuthentication(
options => options =>
{ {

@ -0,0 +1,9 @@
@{
ViewData["Title"] = @SR["Page d'accueil"];
}
@section scripts {
<script src="~/js/str.js">
</script>
}

@ -129,6 +129,10 @@
"target": "project", "target": "project",
"type": "build" "type": "build"
}, },
"OAuth.AspNet.AuthServer": {
"target": "project",
"type": "build"
},
"Microsoft.AspNet.Http.Extensions": "1.0.0-rc1-final", "Microsoft.AspNet.Http.Extensions": "1.0.0-rc1-final",
"Microsoft.DiaSymReader.Native": "1.5.0", "Microsoft.DiaSymReader.Native": "1.5.0",
"PayPalMerchant-net451": "2.7.109", "PayPalMerchant-net451": "2.7.109",

@ -0,0 +1,12 @@
var constraints = { audio: true, video: false }
navigator.mediaDevices.getUserMedia(constraints)
.then(function(stream) {
/* use the stream */
console.log("got stream!");
console.log(stream)
})
.catch(function(err) {
/* handle the error */
console.log(err)
});

@ -3,7 +3,9 @@
"Yavsc", "Yavsc",
"Yavsc.Abstract", "Yavsc.Abstract",
"Yavsc.Server", "Yavsc.Server",
"testOauthClient" "testOauthClient",
"OAuth.AspNet.Token",
"OAuth.AspNet.Server"
], ],
"sdk": { "sdk": {
"version": "1.0.0-rc1-update2", "version": "1.0.0-rc1-update2",

@ -14,6 +14,12 @@
}, },
{ {
"path": "Yavsc.Server" "path": "Yavsc.Server"
},
{
"path": "OAuth.AspNet.AuthServer"
},
{
"path": "OAuth.AspNet.Token"
} }
], ],
"settings": { "settings": {

Loading…