|
|
@ -17,11 +17,11 @@ namespace Yavsc
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private Client GetApplication(string clientId)
|
|
|
|
private Client GetApplication(string clientId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Client app = null;
|
|
|
|
if (_dbContext==null)
|
|
|
|
using (var dbContext = new ApplicationDbContext())
|
|
|
|
logger.LogError("no db!");
|
|
|
|
{
|
|
|
|
Client app = _dbContext.Applications.FirstOrDefault(x => x.Id == clientId);
|
|
|
|
app = dbContext.Applications.FirstOrDefault(x => x.Id == clientId);
|
|
|
|
if (app==null)
|
|
|
|
}
|
|
|
|
logger.LogError("no app!");
|
|
|
|
return app;
|
|
|
|
return app;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private readonly ConcurrentDictionary<string, string> _authenticationCodes = new ConcurrentDictionary<string, string>(StringComparer.Ordinal);
|
|
|
|
private readonly ConcurrentDictionary<string, string> _authenticationCodes = new ConcurrentDictionary<string, string>(StringComparer.Ordinal);
|
|
|
@ -43,12 +43,18 @@ namespace Yavsc
|
|
|
|
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})");
|
|
|
|
logger.LogInformation($"ValidateClientAuthentication: Got id: ({clientId} secret: {clientSecret})");
|
|
|
|
var client = GetApplication(clientId);
|
|
|
|
var client = GetApplication(clientId);
|
|
|
|
|
|
|
|
if (client==null) {
|
|
|
|
|
|
|
|
context.SetError("invalid_clientId", "Client secret is invalid.");
|
|
|
|
|
|
|
|
return Task.FromResult<object>(null);
|
|
|
|
|
|
|
|
} else
|
|
|
|
if (client.Type == ApplicationTypes.NativeConfidential)
|
|
|
|
if (client.Type == ApplicationTypes.NativeConfidential)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
logger.LogInformation($"NativeConfidential key");
|
|
|
|
if (string.IsNullOrWhiteSpace(clientSecret))
|
|
|
|
if (string.IsNullOrWhiteSpace(clientSecret))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
logger.LogInformation($"invalid_clientId: Client secret should be sent.");
|
|
|
|
context.SetError("invalid_clientId", "Client secret should be sent.");
|
|
|
|
context.SetError("invalid_clientId", "Client secret should be sent.");
|
|
|
|
return Task.FromResult<object>(null);
|
|
|
|
return Task.FromResult<object>(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -59,6 +65,7 @@ namespace Yavsc
|
|
|
|
if (client.Secret != clientSecret)
|
|
|
|
if (client.Secret != clientSecret)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
context.SetError("invalid_clientId", "Client secret is invalid.");
|
|
|
|
context.SetError("invalid_clientId", "Client secret is invalid.");
|
|
|
|
|
|
|
|
logger.LogInformation($"invalid_clientId: Client secret is invalid.");
|
|
|
|
return Task.FromResult<object>(null);
|
|
|
|
return Task.FromResult<object>(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -67,6 +74,7 @@ namespace Yavsc
|
|
|
|
if (!client.Active)
|
|
|
|
if (!client.Active)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
context.SetError("invalid_clientId", "Client is inactive.");
|
|
|
|
context.SetError("invalid_clientId", "Client is inactive.");
|
|
|
|
|
|
|
|
logger.LogInformation($"invalid_clientId: Client is inactive.");
|
|
|
|
return Task.FromResult<object>(null);
|
|
|
|
return Task.FromResult<object>(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -75,9 +83,9 @@ 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 logger.LogInformation($":'( ValidateClientAuthentication: KO ({clientId})");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else Startup.logger.LogWarning($"ValidateClientAuthentication: neither Basic nor Form credential were found");
|
|
|
|
else logger.LogWarning($"ValidateClientAuthentication: neither Basic nor Form credential were found");
|
|
|
|
return Task.FromResult(0);
|
|
|
|
return Task.FromResult(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UserManager<ApplicationUser> _usermanager;
|
|
|
|
UserManager<ApplicationUser> _usermanager;
|
|
|
|