refactorisation : separation du code serveur d'authentification
This commit is contained in:
@ -3,7 +3,6 @@ using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.DataProtection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.WebEncoders;
|
||||
using Yavsc.Auth;
|
||||
|
||||
namespace OAuth.AspNet.AuthServer
|
||||
{
|
41
OAuth.AspNet.AuthServer/project.json
Normal file
41
OAuth.AspNet.AuthServer/project.json
Normal file
@ -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": {}
|
||||
}
|
||||
}
|
||||
}
|
3341
OAuth.AspNet.AuthServer/project.lock.json
Normal file
3341
OAuth.AspNet.AuthServer/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -4,37 +4,35 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.AspNet.DataProtection;
|
||||
namespace Yavsc.Auth
|
||||
{
|
||||
|
||||
public class MonoDataProtectionProvider : IDataProtectionProvider
|
||||
{
|
||||
{
|
||||
private readonly string appName;
|
||||
|
||||
public MonoDataProtectionProvider()
|
||||
: this(Guid.NewGuid().ToString())
|
||||
{ }
|
||||
|
||||
public MonoDataProtectionProvider(DirectoryInfo dataProtectionDirInfo)
|
||||
public MonoDataProtectionProvider(DirectoryInfo dataProtectionDirInfo)
|
||||
: this(Guid.NewGuid().ToString())
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
public MonoDataProtectionProvider(string appName)
|
||||
{
|
||||
if (appName == null) { throw new ArgumentNullException("appName"); }
|
||||
this.appName = appName;
|
||||
if (appName == null) { throw new ArgumentNullException("appName"); }
|
||||
this.appName = appName;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return Create(new string[] {purpose});
|
||||
}
|
||||
public IDataProtector CreateProtector(string purpose)
|
||||
{
|
||||
return Create(new string[] { purpose });
|
||||
}
|
||||
}
|
83
OAuth.AspNet.Token/MonoDataProtector.cs
Normal file
83
OAuth.AspNet.Token/MonoDataProtector.cs
Normal file
@ -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.Security.Claims;
|
||||
using System.Text.RegularExpressions;
|
||||
using Yavsc.Auth;
|
||||
using Yavsc;
|
||||
|
||||
namespace OAuth.AspNet.Tokens
|
||||
{
|
||||
@ -20,8 +18,8 @@ namespace OAuth.AspNet.Tokens
|
||||
{
|
||||
if (dataProtectionProvider == null)
|
||||
{
|
||||
dataProtectionProvider = new MonoDataProtectionProvider(Constants.ApplicationName)
|
||||
.CreateProtector(Constants.KeyProtectorPurpose);
|
||||
dataProtectionProvider = new MonoDataProtectionProvider(System.AppDomain.CurrentDomain.FriendlyName)
|
||||
.CreateProtector("profile");
|
||||
}
|
||||
_ticketDataFormat = new TicketDataFormat(dataProtectionProvider.CreateProtector("Access_Token", "v1"));
|
||||
}
|
38
OAuth.AspNet.Token/project.json
Normal file
38
OAuth.AspNet.Token/project.json
Normal file
@ -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": {}
|
||||
}
|
||||
}
|
||||
}
|
1870
OAuth.AspNet.Token/project.lock.json
Normal file
1870
OAuth.AspNet.Token/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
23
Yavsc.Server/Yavsc.Server.nuspec
Normal file
23
Yavsc.Server/Yavsc.Server.nuspec
Normal file
@ -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.Json >= 4.0.0",
|
||||
"fx/System.Net >= 4.0.0",
|
||||
"fx/System.Net.Http >= 4.0.0",
|
||||
"fx/System.Xml >= 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",
|
||||
FrontOfficeGroupName = "FrontOffice",
|
||||
GCMNotificationUrl = "https://gcm-http.googleapis.com/gcm/send",
|
||||
KeyProtectorPurpose = "OAuth.AspNet.AuthServer",
|
||||
UserFilesPath = "/UserFiles",
|
||||
AvatarsPath = "/avatars",
|
||||
DefaultAvatar = "/images/Users/icon_user.png",
|
||||
|
@ -130,10 +130,16 @@ namespace Yavsc.Controllers
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult VideoChat()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
}
|
||||
public IActionResult Audio()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -98,6 +98,7 @@ namespace Yavsc
|
||||
app.UseWhen(context => context.Request.Path.StartsWithSegments("/api"),
|
||||
branch =>
|
||||
{
|
||||
|
||||
branch.UseJwtBearerAuthentication(
|
||||
options =>
|
||||
{
|
||||
|
9
Yavsc/Views/Home/Audio.cshtml
Normal file
9
Yavsc/Views/Home/Audio.cshtml
Normal file
@ -0,0 +1,9 @@
|
||||
@{
|
||||
ViewData["Title"] = @SR["Page d'accueil"];
|
||||
}
|
||||
@section scripts {
|
||||
|
||||
<script src="~/js/str.js">
|
||||
</script>
|
||||
|
||||
}
|
@ -129,6 +129,10 @@
|
||||
"target": "project",
|
||||
"type": "build"
|
||||
},
|
||||
"OAuth.AspNet.AuthServer": {
|
||||
"target": "project",
|
||||
"type": "build"
|
||||
},
|
||||
"Microsoft.AspNet.Http.Extensions": "1.0.0-rc1-final",
|
||||
"Microsoft.DiaSymReader.Native": "1.5.0",
|
||||
"PayPalMerchant-net451": "2.7.109",
|
||||
|
12
Yavsc/wwwroot/js/str.js
Normal file
12
Yavsc/wwwroot/js/str.js
Normal file
@ -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.Abstract",
|
||||
"Yavsc.Server",
|
||||
"testOauthClient"
|
||||
"testOauthClient",
|
||||
"OAuth.AspNet.Token",
|
||||
"OAuth.AspNet.Server"
|
||||
],
|
||||
"sdk": {
|
||||
"version": "1.0.0-rc1-update2",
|
||||
|
@ -14,6 +14,12 @@
|
||||
},
|
||||
{
|
||||
"path": "Yavsc.Server"
|
||||
},
|
||||
{
|
||||
"path": "OAuth.AspNet.AuthServer"
|
||||
},
|
||||
{
|
||||
"path": "OAuth.AspNet.Token"
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
|
Reference in New Issue
Block a user