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

This commit is contained in:
2016-06-15 17:24:37 +02:00
parent 7632de1673
commit 95c694b5e2
198 changed files with 10623 additions and 1836 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

@ -7,6 +7,7 @@ using Microsoft.AspNet.Mvc;
using Yavsc.ViewModels.Account; using Yavsc.ViewModels.Account;
using System.Security.Claims; using System.Security.Claims;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Yavsc.Models.Auth;
namespace Yavsc.WebApi.Controllers namespace Yavsc.WebApi.Controllers
{ {
@ -118,5 +119,18 @@ namespace Yavsc.WebApi.Controllers
base.Dispose(disposing); 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