refactorisation : separation du code serveur d'authentification
parent
815371bfa3
commit
d287eabb48
@ -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
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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>
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,9 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = @SR["Page d'accueil"];
|
||||||
|
}
|
||||||
|
@section scripts {
|
||||||
|
|
||||||
|
<script src="~/js/str.js">
|
||||||
|
</script>
|
||||||
|
|
||||||
|
}
|
@ -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)
|
||||||
|
});
|
Loading…
Reference in New Issue