sépare le modèle client du serveur, et crée par la même la librairie Yavsc.Api

This commit is contained in:
Paul Schneider 2016-06-15 17:24:37 +02:00
commit d3ba13c0cf
101 changed files with 5754 additions and 91 deletions

View file

@ -21,7 +21,7 @@
namespace Yavsc.Models namespace Yavsc.Models.Access
{ {
/// <summary> /// <summary>

View file

@ -21,6 +21,7 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Yavsc.Models.Messaging; using Yavsc.Models.Messaging;
using Yavsc.Models.Access;
namespace Yavsc.Models.Calendar namespace Yavsc.Models.Calendar
{ {

View file

@ -7,7 +7,6 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Yavsc.Models namespace Yavsc.Models
{ {
// Add profile data for application users by adding properties to the ApplicationUser class
public class ApplicationUser : IdentityUser public class ApplicationUser : IdentityUser
{ {

View file

@ -32,7 +32,7 @@ namespace Yavsc.Models.Messaging
/// The name of the NF provider. /// The name of the NF provider.
/// </summary> /// </summary>
[Display(Name="ProviderName")] [Display(Name="ProviderName")]
public string ProviderName { get; set; } = Constants.ApplicationName; public string ProviderName { get; set; }
/// <summary> /// <summary>
/// The NF provider identifier. /// The NF provider identifier.
/// </summary> /// </summary>

7
Yavsc.Api/package.json Normal file
View file

@ -0,0 +1,7 @@
{
"name": "Yavsc.Api",
"version": "0.0.0",
"devDependencies": {
"gulp": "^3.9.0"
}
}

23
Yavsc.Api/project.json Normal file
View file

@ -0,0 +1,23 @@
{
"version": "1.0.0-*",
"description": "Api Class Library",
"authors": [ "Class Library template" ],
"tags": [""],
"projectUrl": "",
"licenseUrl": "",
"tooling": {
"defaultNamespace": "Yavsc"
},
"dependencies": {
"EntityFramework.Commands": "7.0.0-rc1-*",
"EntityFramework.Core": "7.0.0-rc1-*",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-*",
"EntityFramework.Relational": "7.0.0-rc1-*",
"EntityFramework7.Npgsql": "3.1.0-*",
"EntityFramework7.Npgsql.Design": "3.1.0-*",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-*"
},
"frameworks": {
"net451": { }
}
}

View file

@ -119,7 +119,7 @@ namespace Yavsc.WebApi.Controllers
base.Dispose(disposing); base.Dispose(disposing);
} }
[HttpGet("~/api/me"),Produces("application/json")] [HttpGet("~/api/me")]
public async Task<IActionResult> Me () public async Task<IActionResult> Me ()
{ {
if (User==null) if (User==null)

View file

@ -90,6 +90,7 @@ namespace OAuth.AspNet.AuthServer
public bool TryGetFormCredentials(out string clientId, out string clientSecret) public bool TryGetFormCredentials(out string clientId, out string clientSecret)
{ {
clientId = Parameters[Constants.Parameters.ClientId]; clientId = Parameters[Constants.Parameters.ClientId];
if (!string.IsNullOrEmpty(clientId)) if (!string.IsNullOrEmpty(clientId))
{ {
clientSecret = Parameters[Constants.Parameters.ClientSecret]; clientSecret = Parameters[Constants.Parameters.ClientSecret];

View file

@ -99,6 +99,7 @@ namespace Yavsc.Controllers
else else
{ {
ModelState.AddModelError(string.Empty, "Invalid login attempt."); ModelState.AddModelError(string.Empty, "Invalid login attempt.");
model.ExternalProviders = HttpContext.GetExternalProviders();
return View(model); return View(model);
} }
} }

View file

@ -1,16 +0,0 @@
using System.Threading.Tasks;
namespace Yavsc.Interfaces {
public interface IDataStore<T> {
Task StoreAsync (string key, T value);
Task DeleteAsync (string key);
Task<T> GetAsync (string key);
Task ClearAsync ();
}
}

View file

@ -1 +0,0 @@

View file

@ -38,9 +38,11 @@ namespace Yavsc
private Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context) private Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{ {
string clientId, clientSecret; string clientId, clientSecret;
if (context.TryGetBasicCredentials(out clientId, out clientSecret) || if (context.TryGetBasicCredentials(out clientId, out clientSecret) ||
context.TryGetFormCredentials(out clientId, out clientSecret)) context.TryGetFormCredentials(out clientId, out clientSecret))
{ {
logger.LogInformation($"ValidateClientAuthentication: Got id&secret: ({clientId} {clientSecret})");
var client = GetApplication(clientId); var client = GetApplication(clientId);
if (client.Type == ApplicationTypes.NativeConfidential) if (client.Type == ApplicationTypes.NativeConfidential)
{ {
@ -51,7 +53,9 @@ namespace Yavsc
} }
else else
{ {
if (client.Secret != Helper.GetHash(clientSecret)) // if (client.Secret != Helper.GetHash(clientSecret))
// TODO store a hash in db, not the pass
if (client.Secret != clientSecret)
{ {
context.SetError("invalid_clientId", "Client secret is invalid."); context.SetError("invalid_clientId", "Client secret is invalid.");
return Task.FromResult<object>(null); return Task.FromResult<object>(null);
@ -70,7 +74,7 @@ namespace Yavsc
logger.LogInformation($"\\o/ ValidateClientAuthentication: Validated ({clientId})"); logger.LogInformation($"\\o/ ValidateClientAuthentication: Validated ({clientId})");
context.Validated(); context.Validated();
} }
else Startup.logger.LogInformation($"ValidateClientAuthentication: KO ({clientId})"); else Startup.logger.LogInformation($":'( ValidateClientAuthentication: KO ({clientId})");
} }
else Startup.logger.LogWarning($"ValidateClientAuthentication: neither Basic nor Form credential were found"); else Startup.logger.LogWarning($"ValidateClientAuthentication: neither Basic nor Form credential were found");
return Task.FromResult(0); return Task.FromResult(0);

View file

@ -182,6 +182,7 @@ namespace Yavsc
.RequireAuthenticatedUser() .RequireAuthenticatedUser()
.Build(); .Build();
config.Filters.Add(new AuthorizeFilter(policy)); config.Filters.Add(new AuthorizeFilter(policy));
config.Filters.Add(new ProducesAttribute("application/json"));
config.OutputFormatters.Add(new PdfFormatter()); config.OutputFormatters.Add(new PdfFormatter());
}).AddFormatterMappings( }).AddFormatterMappings(

View file

@ -45,11 +45,11 @@
"defaultNamespace": "Yavsc" "defaultNamespace": "Yavsc"
}, },
"dependencies": { "dependencies": {
"Yavsc.Api":"1.0.0",
"EntityFramework.Commands": "7.0.0-rc1-*", "EntityFramework.Commands": "7.0.0-rc1-*",
"EntityFramework.Core": "7.0.0-rc1-*", "EntityFramework.Core": "7.0.0-rc1-*",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-*", "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-*",
"EntityFramework.Relational": "7.0.0-rc1-*", "EntityFramework.Relational": "7.0.0-rc1-*",
"EntityFramework.Sqlite": "7.0.0-rc1-*",
"EntityFramework7.Npgsql": "3.1.0-*", "EntityFramework7.Npgsql": "3.1.0-*",
"EntityFramework7.Npgsql.Design": "3.1.0-*", "EntityFramework7.Npgsql.Design": "3.1.0-*",
"Google.Apis.Core": "1.11.1", "Google.Apis.Core": "1.11.1",

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
{ {
"projects": [ "Yavsc" ], "projects": [ "Yavsc", "Yavsc.Api" ],
"sdk": { "sdk": {
"version": "1.0.0-rc1-update2", "version": "1.0.0-rc1-update2",
"runtime": "mono", "runtime": "mono",

Some files were not shown because too many files have changed in this diff Show more