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

vnext
Paul Schneider 8 years ago
parent 7632de1673
commit 95c694b5e2
198 changed files with 10616 additions and 1829 deletions

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

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

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

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

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

@ -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": { }
}
}

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

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

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

@ -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 ();
}
}

@ -38,9 +38,11 @@ namespace Yavsc
private Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
string clientId, clientSecret;
if (context.TryGetBasicCredentials(out clientId, out clientSecret) ||
context.TryGetFormCredentials(out clientId, out clientSecret))
{
logger.LogInformation($"ValidateClientAuthentication: Got id&secret: ({clientId} {clientSecret})");
var client = GetApplication(clientId);
if (client.Type == ApplicationTypes.NativeConfidential)
{
@ -51,7 +53,9 @@ namespace Yavsc
}
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.");
return Task.FromResult<object>(null);
@ -70,7 +74,7 @@ namespace Yavsc
logger.LogInformation($"\\o/ ValidateClientAuthentication: Validated ({clientId})");
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");
return Task.FromResult(0);

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

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

File diff suppressed because it is too large Load Diff

@ -7,6 +7,7 @@ using Microsoft.AspNet.Mvc;
using Yavsc.ViewModels.Account;
using System.Security.Claims;
using Microsoft.Extensions.Logging;
using Yavsc.Models.Auth;
namespace Yavsc.WebApi.Controllers
{
@ -118,5 +119,18 @@ namespace Yavsc.WebApi.Controllers
base.Dispose(disposing);
}
[HttpGet("~/api/me")]
public async Task<IActionResult> Me ()
{
if (User==null)
return new BadRequestObjectResult(
new { error = "user not found" });
var uid = User.GetUserId();
if (uid == null)
return new BadRequestObjectResult(
new { error = "user not identified" });
return Ok(new Me(await UserManager.FindByIdAsync(uid)));
}
}
}

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

Loading…