An Oauth client handler, from abstract
This commit is contained in:
parent
c590930d09
commit
fca6b46c92
18 changed files with 710 additions and 649 deletions
|
|
@ -18,7 +18,7 @@ namespace Yavsc.Helpers
|
|||
|
||||
public static Stream GetStream(StreamReader reader)
|
||||
{
|
||||
var procStart = new ProcessStartInfo("/usr/bin/nodejs", "node_modules/ansi-to-html/bin/ansi-to-html");
|
||||
var procStart = new ProcessStartInfo("node", "node_modules/ansi-to-html/bin/ansi-to-html");
|
||||
procStart.UseShellExecute = false;
|
||||
procStart.RedirectStandardInput = true;
|
||||
procStart.RedirectStandardOutput = true;
|
||||
|
|
|
|||
|
|
@ -18,9 +18,10 @@ namespace Yavsc
|
|||
{
|
||||
private Client GetApplication(string clientId)
|
||||
{
|
||||
Client app=null;
|
||||
using (var dbContext = new ApplicationDbContext()) {
|
||||
app = dbContext.Applications.FirstOrDefault(x => x.Id == clientId);
|
||||
Client app = null;
|
||||
using (var dbContext = new ApplicationDbContext())
|
||||
{
|
||||
app = dbContext.Applications.FirstOrDefault(x => x.Id == clientId);
|
||||
}
|
||||
return app;
|
||||
}
|
||||
|
|
@ -39,7 +40,7 @@ namespace Yavsc
|
|||
private Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
|
||||
{
|
||||
string clientId, clientSecret;
|
||||
|
||||
|
||||
if (context.TryGetBasicCredentials(out clientId, out clientSecret) ||
|
||||
context.TryGetFormCredentials(out clientId, out clientSecret))
|
||||
{
|
||||
|
|
@ -54,9 +55,9 @@ namespace Yavsc
|
|||
}
|
||||
else
|
||||
{
|
||||
// if (client.Secret != Helper.GetHash(clientSecret))
|
||||
// TODO store a hash in db, not the pass
|
||||
if (client.Secret != 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);
|
||||
|
|
@ -80,38 +81,36 @@ namespace Yavsc
|
|||
else Startup.logger.LogWarning($"ValidateClientAuthentication: neither Basic nor Form credential were found");
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
UserManager<ApplicationUser> _usermanager;
|
||||
|
||||
private async Task<Task> GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
|
||||
{
|
||||
logger.LogWarning($"GrantResourceOwnerCredentials task ... {context.UserName}");
|
||||
|
||||
ApplicationUser user = null;
|
||||
using (var usermanager = context.HttpContext.ApplicationServices.GetRequiredService<UserManager<ApplicationUser>>())
|
||||
{
|
||||
user = await usermanager.FindByNameAsync(context.UserName);
|
||||
if (await usermanager.CheckPasswordAsync(user,context.Password))
|
||||
{
|
||||
user = await _usermanager.FindByNameAsync(context.UserName);
|
||||
if (await _usermanager.CheckPasswordAsync(user, context.Password))
|
||||
{
|
||||
|
||||
var claims = new List<Claim>(
|
||||
context.Scope.Select(x => new Claim("urn:oauth:scope", x))
|
||||
);
|
||||
claims.Add(new Claim(ClaimTypes.NameIdentifier,user.Id));
|
||||
claims.Add(new Claim(ClaimTypes.Email,user.Email));
|
||||
claims.AddRange((await usermanager.GetRolesAsync(user)).Select(
|
||||
r => new Claim(ClaimTypes.Role,r)
|
||||
) );
|
||||
ClaimsPrincipal principal = new ClaimsPrincipal(
|
||||
new ClaimsIdentity(
|
||||
new GenericIdentity(context.UserName, OAuthDefaults.AuthenticationType),
|
||||
claims)
|
||||
);
|
||||
// TODO set a NameIdentifier, roles and scopes claims
|
||||
context.HttpContext.User = principal;
|
||||
var claims = new List<Claim>(
|
||||
context.Scope.Select(x => new Claim("urn:oauth:scope", x))
|
||||
);
|
||||
claims.Add(new Claim(ClaimTypes.NameIdentifier, user.Id));
|
||||
claims.Add(new Claim(ClaimTypes.Email, user.Email));
|
||||
claims.AddRange((await _usermanager.GetRolesAsync(user)).Select(
|
||||
r => new Claim(ClaimTypes.Role, r)
|
||||
));
|
||||
ClaimsPrincipal principal = new ClaimsPrincipal(
|
||||
new ClaimsIdentity(
|
||||
new GenericIdentity(context.UserName, OAuthDefaults.AuthenticationType),
|
||||
claims)
|
||||
);
|
||||
// TODO set a NameIdentifier, roles and scopes claims
|
||||
context.HttpContext.User = principal;
|
||||
|
||||
context.Validated(principal);
|
||||
}
|
||||
|
||||
context.Validated(principal);
|
||||
}
|
||||
}
|
||||
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ namespace Yavsc
|
|||
using System.Net;
|
||||
using Formatters;
|
||||
using Google.Apis.Util.Store;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Models;
|
||||
using PayPal.Manager;
|
||||
|
|
@ -263,9 +264,10 @@ namespace Yavsc
|
|||
IOptions<PayPalSettings> payPalSettings,
|
||||
IOptions<GoogleAuthSettings> googleSettings,
|
||||
IStringLocalizer<Yavsc.Resources.YavscLocalisation> localizer,
|
||||
UserManager<ApplicationUser> usermanager,
|
||||
ILoggerFactory loggerFactory)
|
||||
{
|
||||
|
||||
_usermanager = usermanager;
|
||||
GoogleSettings = googleSettings.Value;
|
||||
ResourcesHelpers.GlobalLocalizer = localizer;
|
||||
SiteSetup = siteSettings.Value;
|
||||
|
|
|
|||
|
|
@ -31,10 +31,6 @@ gulp.task("clean:css", function(cb) {
|
|||
|
||||
gulp.task("clean", ["clean:js", "clean:css"]);
|
||||
|
||||
gulp.task('watch', shell.task(['ASPNET_ENV=Development dnx-watch web --configuration=Debug']));
|
||||
gulp.task('watchlua', shell.task(['ASPNET_ENV=lua dnx-watch luatest --configuration=Debug']));
|
||||
gulp.task('watchpre', shell.task(['ASPNET_ENV=yavscpre dnx-watch web --configuration=Debug']));
|
||||
|
||||
gulp.task("min:css", function() {
|
||||
gulp.src([paths.css, "!" + paths.minCss, '!site.css'])
|
||||
.pipe(cssmin())
|
||||
|
|
@ -56,4 +52,4 @@ gulp.task('run', shell.task(['ASPNET_ENV=Development dnx web --configuration=Deb
|
|||
gulp.task('buildrelease', shell.task(['dnu build --configuration=Release']));
|
||||
|
||||
|
||||
gulp.task("default", ["watch"]);
|
||||
gulp.task("default", ["min"]);
|
||||
|
|
|
|||
1004
Yavsc/package-lock.json
generated
1004
Yavsc/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,26 +1,26 @@
|
|||
{
|
||||
"name": "yavsc",
|
||||
"version": "1.0.1",
|
||||
"description": "Yet Another Very Small Company",
|
||||
"repository": {
|
||||
"type": "Git",
|
||||
"url": "https://github.com/pazof/yavsc"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"devDependencies": {
|
||||
"grunt": "^1.0.2",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-clean": "^0.4.0",
|
||||
"gulp-concat": "2.6.1",
|
||||
"gulp-cssmin": "^0.2.0",
|
||||
"gulp-dnx-tasks": "^1.0.0-beta7",
|
||||
"gulp-shell": "^0.6.5",
|
||||
"gulp-uglify": "^3.0.0",
|
||||
"rimraf": "^2.6.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"ansi-to-html": "^0.6.4",
|
||||
"braintree-web": "^3.31.0",
|
||||
"paypal-permissions-sdk": "^1.0.10"
|
||||
}
|
||||
"name": "yavsc",
|
||||
"version": "1.0.1",
|
||||
"description": "Yet Another Very Small Company",
|
||||
"repository": {
|
||||
"type": "Git",
|
||||
"url": "https://github.com/pazof/yavsc"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"devDependencies": {
|
||||
"grunt": "^1.0.2",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-clean": "^0.4.0",
|
||||
"gulp-concat": "2.6.1",
|
||||
"gulp-cssmin": "^0.2.0",
|
||||
"gulp-dnx-tasks": "^1.0.0-beta7",
|
||||
"gulp-shell": "^0.6.5",
|
||||
"gulp-uglify": "^3.0.0",
|
||||
"rimraf": "^2.6.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"ansi-to-html": "^0.6.4",
|
||||
"braintree-web": "^3.31.0",
|
||||
"paypal-permissions-sdk": "^1.0.10"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue