FIXME SR is private
This commit is contained in:
parent
8929cc9bfa
commit
123283f277
576 changed files with 75350 additions and 13070 deletions
|
|
@ -1,27 +1,20 @@
|
|||
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Services;
|
||||
using Yavsc.ViewModels.Account;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Data.Entity;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Yavsc.Abstract.Manage;
|
||||
using Yavsc.Auth;
|
||||
using Yavsc.Helpers;
|
||||
|
||||
public class AccountController : Controller
|
||||
|
|
@ -54,11 +47,6 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
_userManager = userManager;
|
||||
_signInManager = signInManager;
|
||||
var emailUserTokenProvider = new UserTokenProvider();
|
||||
_userManager.RegisterTokenProvider("EmailConfirmation", emailUserTokenProvider);
|
||||
_userManager.RegisterTokenProvider("ResetPassword", emailUserTokenProvider);
|
||||
// _userManager.RegisterTokenProvider("SMS",new UserTokenProvider());
|
||||
// _userManager.RegisterTokenProvider("Phone", new UserTokenProvider());
|
||||
_emailSender = emailSender;
|
||||
_siteSettings = siteSettings.Value;
|
||||
_twilioSettings = twilioSettings.Value;
|
||||
|
|
@ -86,7 +74,7 @@ namespace Yavsc.Controllers
|
|||
var toShow = users.Skip(shown).Take(pageLen);
|
||||
|
||||
ViewBag.page = pageNum;
|
||||
ViewBag.hasNext = await users.CountAsync() > (toShow.Count() + shown);
|
||||
ViewBag.hasNext = users.Count() > (toShow.Count() + shown);
|
||||
ViewBag.nextpage = pageNum+1;
|
||||
ViewBag.pageLen = pageLen;
|
||||
// ApplicationUser user;
|
||||
|
|
@ -122,7 +110,8 @@ namespace Yavsc.Controllers
|
|||
[AllowAnonymous]
|
||||
public ActionResult AccessDenied(string requestUrl = null)
|
||||
{
|
||||
ViewBag.UserIsSignedIn = User.IsSignedIn();
|
||||
ViewBag.UserIsSignedIn = User.Identity.IsAuthenticated;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(requestUrl))
|
||||
if (string.IsNullOrWhiteSpace(Request.Headers["Referer"]))
|
||||
requestUrl = "/";
|
||||
|
|
@ -198,13 +187,7 @@ namespace Yavsc.Controllers
|
|||
if (string.IsNullOrEmpty(model.Provider))
|
||||
{
|
||||
_logger.LogWarning("Provider not specified");
|
||||
return HttpBadRequest();
|
||||
}
|
||||
|
||||
if (!_signInManager.GetExternalAuthenticationSchemes().Any(x => x.AuthenticationScheme == model.Provider))
|
||||
{
|
||||
_logger.LogWarning($"Provider not found : {model.Provider}");
|
||||
return HttpBadRequest();
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
// Instruct the middleware corresponding to the requested external identity
|
||||
|
|
@ -217,7 +200,7 @@ namespace Yavsc.Controllers
|
|||
if (string.IsNullOrEmpty(model.ReturnUrl))
|
||||
{
|
||||
_logger.LogWarning("ReturnUrl not specified");
|
||||
return HttpBadRequest();
|
||||
return BadRequest();
|
||||
}
|
||||
// Note: this still is not the redirect uri given to the third party provider, at building the challenge.
|
||||
var redirectUrl = Url.Action("ExternalLoginCallback", "Account", new { model.ReturnUrl }, protocol:"https", host: Startup.Authority);
|
||||
|
|
@ -364,7 +347,8 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
|
||||
// Sign in the user with this external login provider if the user already has a login.
|
||||
info.ProviderDisplayName = info.ExternalPrincipal.Claims.First(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name")?.Value;
|
||||
throw new NotImplementedException();
|
||||
// info.ProviderDisplayName = info.ExternalPrincipal.Claims.First(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name")?.Value;
|
||||
|
||||
var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false);
|
||||
if (result.Succeeded)
|
||||
|
|
@ -392,9 +376,9 @@ namespace Yavsc.Controllers
|
|||
// If the user does not have an account, then ask the user to create an account.
|
||||
ViewData["ReturnUrl"] = returnUrl;
|
||||
ViewData["LoginProvider"] = info.LoginProvider;
|
||||
var email = info.ExternalPrincipal.FindFirstValue(ClaimTypes.Email);
|
||||
var name = info.ExternalPrincipal.FindFirstValue(ClaimTypes.Name);
|
||||
var avatar = info.ExternalPrincipal.FindFirstValue("urn:google:profile");
|
||||
var email = info.AuthenticationProperties.GetParameter<string>(ClaimTypes.Email);
|
||||
var name = info.AuthenticationProperties.GetParameter<string>(ClaimTypes.Name);
|
||||
var avatar = info.AuthenticationProperties.GetParameter<string>("urn:google:profile");
|
||||
/* var phone = info.ExternalPrincipal.FindFirstValue(ClaimTypes.HomePhone);
|
||||
var mobile = info.ExternalPrincipal.FindFirstValue(ClaimTypes.MobilePhone);
|
||||
var postalcode = info.ExternalPrincipal.FindFirstValue(ClaimTypes.PostalCode);
|
||||
|
|
@ -403,9 +387,9 @@ namespace Yavsc.Controllers
|
|||
foreach (var claim in info.ExternalPrincipal.Claims)
|
||||
_logger.LogWarning("# {0} Claim: {1} {2}", info.LoginProvider, claim.Type, claim.Value);
|
||||
*/
|
||||
var access_token = info.ExternalPrincipal.FindFirstValue("access_token");
|
||||
var token_type = info.ExternalPrincipal.FindFirstValue("token_type");
|
||||
var expires_in = info.ExternalPrincipal.FindFirstValue("expires_in");
|
||||
var access_token = info.AuthenticationProperties.GetParameter<string>("access_token");
|
||||
var token_type = info.AuthenticationProperties.GetParameter<string>("token_type");
|
||||
var expires_in = info.AuthenticationProperties.GetParameter<string>("expires_in");
|
||||
|
||||
return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel
|
||||
{
|
||||
|
|
@ -439,7 +423,8 @@ namespace Yavsc.Controllers
|
|||
var result = await _userManager.CreateAsync(user);
|
||||
if (result.Succeeded)
|
||||
{
|
||||
info.ProviderDisplayName = info.ExternalPrincipal.Claims.First(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name")?.Value;
|
||||
throw new NotImplementedException();
|
||||
// info.ProviderDisplayName = info.Claims.First(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name")?.Value;
|
||||
|
||||
result = await _userManager.AddLoginAsync(user, info);
|
||||
if (result.Succeeded)
|
||||
|
|
|
|||
|
|
@ -1,27 +1,22 @@
|
|||
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
using Microsoft.Data.Entity;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Yavsc.Models.Workflow;
|
||||
using Yavsc.Helpers;
|
||||
using Yavsc.Models.Relationship;
|
||||
using Yavsc.Models.Bank;
|
||||
using Yavsc.ViewModels.Calendar;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Services;
|
||||
using Yavsc.ViewModels.Manage;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
using Yavsc.Helpers;
|
||||
using Models.Relationship;
|
||||
using Models.Bank;
|
||||
using ViewModels.Calendar;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Services;
|
||||
using Yavsc.ViewModels.Manage;
|
||||
using System.IO;
|
||||
|
||||
public class ManageController : Controller
|
||||
{
|
||||
|
|
@ -298,7 +293,7 @@ namespace Yavsc.Controllers
|
|||
public async Task<IActionResult> SetGoogleCalendar(string returnUrl, string pageToken)
|
||||
|
||||
{
|
||||
var uid = User.GetUserId();
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
|
||||
var calendars = await _calendarManager.GetCalendarsAsync(pageToken);
|
||||
return View(new SetGoogleCalendarViewModel {
|
||||
|
|
@ -321,7 +316,7 @@ namespace Yavsc.Controllers
|
|||
[HttpGet]
|
||||
public async Task<IActionResult> AddBankInfo()
|
||||
{
|
||||
var uid = User.GetUserId();
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var user = await _dbContext.Users.Include(u=>u.BankInfo).SingleAsync(u=>u.Id==uid);
|
||||
|
||||
return View(user.BankInfo);
|
||||
|
|
@ -333,7 +328,7 @@ namespace Yavsc.Controllers
|
|||
if (ModelState.IsValid)
|
||||
{
|
||||
// TODO PostBankInfoRequirement & auth
|
||||
var uid = User.GetUserId();
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var user = _dbContext.Users.Include(u=>u.BankInfo)
|
||||
.Single(u=>u.Id == uid);
|
||||
|
||||
|
|
@ -496,13 +491,12 @@ namespace Yavsc.Controllers
|
|||
return View("Error");
|
||||
}
|
||||
var userLogins = await _userManager.GetLoginsAsync(user);
|
||||
var otherLogins = _signInManager.GetExternalAuthenticationSchemes().Where(auth => userLogins.All(ul => auth.AuthenticationScheme != ul.LoginProvider)).ToList();
|
||||
|
||||
ViewData["ShowRemoveButton"] = user.PasswordHash != null || userLogins.Count > 1;
|
||||
|
||||
return View(new ManageLoginsViewModel
|
||||
{
|
||||
CurrentLogins = userLogins,
|
||||
OtherLogins = otherLogins
|
||||
CurrentLogins = userLogins
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -720,7 +714,7 @@ namespace Yavsc.Controllers
|
|||
[HttpGet]
|
||||
public async Task <IActionResult> SetAddress()
|
||||
{
|
||||
var uid = User.GetUserId();
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var user = await _dbContext.Users.Include(u=>u.PostalAddress).SingleAsync(u=>u.Id==uid);
|
||||
ViewBag.GoogleSettings = _googleSettings;
|
||||
return View (user.PostalAddress ?? new Location());
|
||||
|
|
@ -730,7 +724,7 @@ namespace Yavsc.Controllers
|
|||
public async Task <IActionResult> SetAddress(Location model)
|
||||
{
|
||||
if (ModelState.IsValid) {
|
||||
var uid = User.GetUserId();
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
|
||||
var user = _dbContext.Users.Include(u=>u.PostalAddress).Single(u=>u.Id==uid);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,148 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.DataProtection.KeyManagement;
|
||||
using Microsoft.AspNet.Http.Authentication;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.WebUtilities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using OAuth.AspNet.AuthServer;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Auth;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[AllowAnonymous]
|
||||
public class OAuthController : Controller
|
||||
{
|
||||
readonly ILogger _logger;
|
||||
|
||||
public OAuthController(ILoggerFactory loggerFactory)
|
||||
{
|
||||
_logger = loggerFactory.CreateLogger<OAuthController>();
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("~/api/getclaims"), Produces("application/json")]
|
||||
|
||||
public IActionResult GetClaims()
|
||||
{
|
||||
var identity = User.Identity as ClaimsIdentity;
|
||||
|
||||
var claims = from c in identity.Claims
|
||||
select new
|
||||
{
|
||||
subject = c.Subject.Name,
|
||||
type = c.Type,
|
||||
value = c.Value
|
||||
};
|
||||
|
||||
return Ok(claims);
|
||||
}
|
||||
|
||||
[HttpGet(Constants.AuthorizePath),HttpPost(Constants.AuthorizePath)]
|
||||
public async Task<ActionResult> Authorize()
|
||||
{
|
||||
if (Response.StatusCode != 200)
|
||||
{
|
||||
if (Request.Headers.Keys.Contains("Accept")) {
|
||||
var accepted = Request.Headers["Accept"];
|
||||
if (accepted.Contains("application/json"))
|
||||
{
|
||||
_logger.LogError("Invalid http status at authorisation");
|
||||
return new BadRequestObjectResult(new { error = Response.StatusCode} );
|
||||
}
|
||||
}
|
||||
|
||||
return View("AuthorizeError");
|
||||
}
|
||||
|
||||
AuthenticationManager authentication = Request.HttpContext.Authentication;
|
||||
var appAuthSheme = Startup.IdentityAppOptions.Cookies.ApplicationCookieAuthenticationScheme;
|
||||
|
||||
ClaimsPrincipal principal = await authentication.AuthenticateAsync(appAuthSheme);
|
||||
|
||||
if (principal == null)
|
||||
{
|
||||
await authentication.ChallengeAsync(appAuthSheme);
|
||||
|
||||
if (Response.StatusCode == 200)
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
return new HttpStatusCodeResult(Response.StatusCode);
|
||||
}
|
||||
|
||||
string[] scopes = { };
|
||||
string redirect_uri=null;
|
||||
|
||||
IDictionary<string,StringValues> queryStringComponents = null;
|
||||
|
||||
if (Request.QueryString.HasValue)
|
||||
{
|
||||
queryStringComponents = QueryHelpers.ParseQuery(Request.QueryString.Value);
|
||||
|
||||
if (queryStringComponents.ContainsKey("scope"))
|
||||
scopes = ((string)queryStringComponents["scope"]).Split(' ');
|
||||
if (queryStringComponents.ContainsKey("redirect_uri"))
|
||||
redirect_uri = queryStringComponents["redirect_uri"];
|
||||
}
|
||||
var username = User.GetUserName();
|
||||
|
||||
var model = new AuthorisationView {
|
||||
Scopes = (Constants.SiteScopes.Where(s=> scopes.Contains(s.Id))).ToArray(),
|
||||
Message = $"Bienvenue {username}."
|
||||
} ;
|
||||
|
||||
if (Request.Method == "POST")
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Request.Form["submit.Grant"]))
|
||||
{
|
||||
principal = new ClaimsPrincipal(principal.Identities);
|
||||
|
||||
ClaimsIdentity primaryIdentity = (ClaimsIdentity)principal.Identity;
|
||||
|
||||
foreach (var scope in scopes)
|
||||
{
|
||||
primaryIdentity.AddClaim(new Claim("urn:oauth:scope", scope));
|
||||
}
|
||||
await authentication.SignInAsync(OAuthDefaults.AuthenticationType, principal);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Request.Form["submit.Deny"]))
|
||||
{
|
||||
await authentication.SignOutAsync(appAuthSheme);
|
||||
if (redirect_uri!=null)
|
||||
return Redirect(redirect_uri+"?error=scope-denied");
|
||||
return Redirect("/");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Request.Form["submit.Login"]))
|
||||
{
|
||||
await authentication.SignOutAsync(appAuthSheme);
|
||||
await authentication.ChallengeAsync(appAuthSheme);
|
||||
return new HttpUnauthorizedResult();
|
||||
}
|
||||
}
|
||||
|
||||
if (Request.Headers.Keys.Contains("Accept")) {
|
||||
var accepted = Request.Headers["Accept"];
|
||||
if (accepted.Contains("application/json"))
|
||||
{
|
||||
_logger.LogInformation("serving available scopes");
|
||||
return Ok(model);
|
||||
}
|
||||
}
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpGet("~/oauth/success")]
|
||||
public IActionResult NativeAuthSuccess ()
|
||||
{
|
||||
return RedirectToAction("Index","Home");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Yavsc.Models;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
|
|
@ -29,13 +29,13 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
if (id == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
ApplicationUser applicationUser = await _context.ApplicationUser.SingleAsync(m => m.Id == id);
|
||||
if (applicationUser == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return View(applicationUser);
|
||||
|
|
@ -68,13 +68,13 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
if (id == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
ApplicationUser applicationUser = await _context.ApplicationUser.SingleAsync(m => m.Id == id);
|
||||
if (applicationUser == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
return NotFound();
|
||||
}
|
||||
ViewData["PostalAddressId"] = new SelectList(_context.Locations, "Id", "PostalAddress", applicationUser.PostalAddressId);
|
||||
return View(applicationUser);
|
||||
|
|
@ -101,13 +101,13 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
if (id == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
ApplicationUser applicationUser = await _context.ApplicationUser.SingleAsync(m => m.Id == id);
|
||||
if (applicationUser == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return View(applicationUser);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue