React to AuthN/Z changes
This commit is contained in:
parent
97d9b2e385
commit
850ba6375d
|
|
@ -142,7 +142,7 @@ namespace MusicStore.Controllers
|
|||
|
||||
private async Task<ApplicationUser> GetCurrentUserAsync()
|
||||
{
|
||||
return await UserManager.FindByIdAsync(Context.User.Identity.GetUserId());
|
||||
return await UserManager.FindByIdAsync(Context.User.GetUserId());
|
||||
}
|
||||
|
||||
public enum ManageMessageId
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
@model MusicStore.Models.ManageUserViewModel
|
||||
|
||||
<p>You're logged in as <strong>@User.Identity.GetUserName()</strong>.</p>
|
||||
<p>You're logged in as <strong>@User.GetUserName()</strong>.</p>
|
||||
|
||||
@using (Html.BeginForm("Manage", "Account", FormMethod.Post,
|
||||
new { @class = "form-horizontal",
|
||||
|
|
|
|||
|
|
@ -14,15 +14,15 @@
|
|||
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li>
|
||||
@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Manage", "Account", routeValues: null, htmlAttributes: new { title = "Manage" })
|
||||
@Html.ActionLink("Hello " + User.GetUserName() + "!", "Manage", "Account", routeValues: null, htmlAttributes: new { title = "Manage" })
|
||||
</li>
|
||||
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
|
||||
</ul>
|
||||
|
||||
@Html.Json(new {
|
||||
isAuthenticated = true,
|
||||
userName = User.Identity.GetUserName(),
|
||||
userId = User.Identity.GetUserId(),
|
||||
userName = User.GetUserName(),
|
||||
userId = User.GetUserId(),
|
||||
roles = ((ClaimsPrincipal)User).Claims
|
||||
.Where(c => c.Type == ClaimTypes.Role)
|
||||
.Select(role => role.Value),
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ using MusicStore.ViewModels;
|
|||
namespace MusicStore.Areas.Admin.Controllers
|
||||
{
|
||||
[Area("Admin")]
|
||||
[Microsoft.AspNet.Security.Authorize("ManageStore")]
|
||||
[Microsoft.AspNet.Authorization.Authorize("ManageStore")]
|
||||
public class StoreManagerController : Controller
|
||||
{
|
||||
private IConnectionManager _connectionManager;
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
using System.Security.Claims;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.Security;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using MusicStore.Models;
|
||||
|
||||
|
|
@ -371,7 +371,7 @@ namespace MusicStore.Controllers
|
|||
ViewBag.ReturnUrl = returnUrl;
|
||||
ViewBag.LoginProvider = loginInfo.LoginProvider;
|
||||
// REVIEW: handle case where email not in claims?
|
||||
var email = loginInfo.ExternalIdentity.FindFirstValue(ClaimTypes.Email);
|
||||
var email = loginInfo.ExternalPrincipal.FindFirstValue(ClaimTypes.Email);
|
||||
return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = email });
|
||||
}
|
||||
}
|
||||
|
|
@ -383,7 +383,7 @@ namespace MusicStore.Controllers
|
|||
[ValidateAntiForgeryToken]
|
||||
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl = null)
|
||||
{
|
||||
if (User.Identity.IsAuthenticated)
|
||||
if (User.IsSignedIn())
|
||||
{
|
||||
return RedirectToAction("Index", "Manage");
|
||||
}
|
||||
|
|
@ -401,7 +401,7 @@ namespace MusicStore.Controllers
|
|||
|
||||
#if TESTING
|
||||
//Just for automated testing adding a claim named 'ManageStore' - Not required for production
|
||||
var manageClaim = info.ExternalIdentity.Claims.Where(c => c.Type == "ManageStore").FirstOrDefault();
|
||||
var manageClaim = info.ExternalPrincipal.Claims.Where(c => c.Type == "ManageStore").FirstOrDefault();
|
||||
if (manageClaim != null)
|
||||
{
|
||||
await UserManager.AddClaimAsync(user, manageClaim);
|
||||
|
|
@ -463,7 +463,7 @@ namespace MusicStore.Controllers
|
|||
|
||||
private async Task<ApplicationUser> GetCurrentUserAsync()
|
||||
{
|
||||
return await UserManager.FindByIdAsync(Context.User.Identity.GetUserId());
|
||||
return await UserManager.FindByIdAsync(Context.User.GetUserId());
|
||||
}
|
||||
|
||||
private ActionResult RedirectToLocal(string returnUrl)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using System.Security.Principal;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Security;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using MusicStore.Models;
|
||||
|
||||
namespace MusicStore.Controllers
|
||||
|
|
@ -42,7 +42,7 @@ namespace MusicStore.Controllers
|
|||
}
|
||||
else
|
||||
{
|
||||
order.Username = Context.User.Identity.GetUserName();
|
||||
order.Username = Context.User.GetUserName();
|
||||
order.OrderDate = DateTime.Now;
|
||||
|
||||
//Add the Order
|
||||
|
|
@ -73,7 +73,7 @@ namespace MusicStore.Controllers
|
|||
// Validate customer owns this order
|
||||
bool isValid = await DbContext.Orders.AnyAsync(
|
||||
o => o.OrderId == id &&
|
||||
o.Username == Context.User.Identity.GetUserName());
|
||||
o.Username == Context.User.GetUserName());
|
||||
|
||||
if (isValid)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
using System.Linq;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Security;
|
||||
using MusicStore.Models;
|
||||
|
||||
namespace MusicStore.Controllers
|
||||
|
|
@ -287,7 +287,7 @@ namespace MusicStore.Controllers
|
|||
return View("Error");
|
||||
}
|
||||
var userLogins = await UserManager.GetLoginsAsync(user);
|
||||
var otherLogins = SignInManager.GetExternalAuthenticationTypes().Where(auth => userLogins.All(ul => auth.AuthenticationType != ul.LoginProvider)).ToList();
|
||||
var otherLogins = SignInManager.GetExternalAuthenticationSchemes().Where(auth => userLogins.All(ul => auth.AuthenticationScheme != ul.LoginProvider)).ToList();
|
||||
ViewBag.ShowRemoveButton = user.PasswordHash != null || userLogins.Count > 1;
|
||||
return View(new ManageLoginsViewModel
|
||||
{
|
||||
|
|
@ -304,7 +304,7 @@ namespace MusicStore.Controllers
|
|||
{
|
||||
// Request a redirect to the external login provider to link a login for the current user
|
||||
var redirectUrl = Url.Action("LinkLoginCallback", "Manage");
|
||||
var properties = SignInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, User.Identity.GetUserId());
|
||||
var properties = SignInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, User.GetUserId());
|
||||
return new ChallengeResult(provider, properties);
|
||||
}
|
||||
|
||||
|
|
@ -318,7 +318,7 @@ namespace MusicStore.Controllers
|
|||
return View("Error");
|
||||
}
|
||||
|
||||
var loginInfo = await SignInManager.GetExternalLoginInfoAsync(User.Identity.GetUserId());
|
||||
var loginInfo = await SignInManager.GetExternalLoginInfoAsync(User.GetUserId());
|
||||
if (loginInfo == null)
|
||||
{
|
||||
return RedirectToAction("ManageLogins", new { Message = ManageMessageId.Error });
|
||||
|
|
@ -353,7 +353,7 @@ namespace MusicStore.Controllers
|
|||
|
||||
private async Task<ApplicationUser> GetCurrentUserAsync()
|
||||
{
|
||||
return await UserManager.FindByIdAsync(Context.User.Identity.GetUserId());
|
||||
return await UserManager.FindByIdAsync(Context.User.GetUserId());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.AspNet.Http.Security;
|
||||
using Microsoft.AspNet.Http.Authentication;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@ using Microsoft.AspNet.Builder;
|
|||
using Microsoft.AspNet.Diagnostics;
|
||||
using Microsoft.AspNet.Diagnostics.Entity;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Security;
|
||||
using Microsoft.AspNet.Authentication;
|
||||
using Microsoft.Framework.Cache.Memory;
|
||||
using Microsoft.Framework.ConfigurationModel;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Logging;
|
||||
using Microsoft.Framework.Logging.Console;
|
||||
using MusicStore.Models;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
|
||||
namespace MusicStore
|
||||
{
|
||||
|
|
@ -93,7 +94,7 @@ namespace MusicStore
|
|||
// Configure Auth
|
||||
services.Configure<AuthorizationOptions>(options =>
|
||||
{
|
||||
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("ManageStore", "Allowed").Build());
|
||||
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using System.Security.Principal;
|
|||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Diagnostics;
|
||||
using Microsoft.AspNet.Diagnostics.Entity;
|
||||
using Microsoft.AspNet.Security;
|
||||
using Microsoft.AspNet.Authentication;
|
||||
using Microsoft.AspNet.Server.WebListener;
|
||||
using Microsoft.Framework.Cache.Memory;
|
||||
using Microsoft.Framework.ConfigurationModel;
|
||||
|
|
@ -13,6 +13,7 @@ using Microsoft.Framework.Logging;
|
|||
using Microsoft.Framework.Logging.Console;
|
||||
using Microsoft.Net.Http.Server;
|
||||
using MusicStore.Models;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
|
||||
namespace MusicStore
|
||||
{
|
||||
|
|
@ -65,7 +66,7 @@ namespace MusicStore
|
|||
// Configure Auth
|
||||
services.Configure<AuthorizationOptions>(options =>
|
||||
{
|
||||
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("ManageStore", "Allowed").Build());
|
||||
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +85,7 @@ namespace MusicStore
|
|||
if ((app.Server as ServerInformation) != null)
|
||||
{
|
||||
var serverInformation = (ServerInformation)app.Server;
|
||||
serverInformation.Listener.AuthenticationManager.AuthenticationTypes = AuthenticationTypes.NTLM;
|
||||
serverInformation.Listener.AuthenticationManager.AuthenticationSchemes = AuthenticationSchemes.NTLM;
|
||||
}
|
||||
|
||||
app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
|
||||
|
|
@ -99,7 +100,7 @@ namespace MusicStore
|
|||
//Who will get admin access? For demo sake I'm listing the currently logged on user as the application administrator. But this can be changed to suit the needs.
|
||||
var identity = (ClaimsIdentity)context.User.Identity;
|
||||
|
||||
if (identity.GetUserName() == Environment.GetEnvironmentVariable("USERDOMAIN") + "\\" + Environment.GetEnvironmentVariable("USERNAME"))
|
||||
if (context.User.GetUserName() == Environment.GetEnvironmentVariable("USERDOMAIN") + "\\" + Environment.GetEnvironmentVariable("USERNAME"))
|
||||
{
|
||||
identity.AddClaim(new Claim("ManageStore", "Allowed"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@ using Microsoft.AspNet.Builder;
|
|||
using Microsoft.AspNet.Diagnostics;
|
||||
using Microsoft.AspNet.Diagnostics.Entity;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Security;
|
||||
using Microsoft.AspNet.Authentication;
|
||||
using Microsoft.Framework.Cache.Memory;
|
||||
using Microsoft.Framework.ConfigurationModel;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Logging;
|
||||
using Microsoft.Framework.Logging.Console;
|
||||
using MusicStore.Models;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
|
||||
namespace MusicStore
|
||||
{
|
||||
|
|
@ -81,7 +82,7 @@ namespace MusicStore
|
|||
// Configure Auth
|
||||
services.Configure<AuthorizationOptions>(options =>
|
||||
{
|
||||
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("ManageStore", "Allowed").Build());
|
||||
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<h4>Use another service to log in.</h4>
|
||||
<hr />
|
||||
@{
|
||||
var loginProviders = SignInManager.GetExternalAuthenticationTypes();
|
||||
var loginProviders = SignInManager.GetExternalAuthenticationSchemes();
|
||||
if (loginProviders.Count() == 0)
|
||||
{
|
||||
<div>
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
<p>
|
||||
@foreach (AuthenticationDescription p in loginProviders.Where(a => a.Caption != null))
|
||||
{
|
||||
<button type="submit" class="btn btn-default" id="@p.AuthenticationType" name="provider" value="@p.AuthenticationType" title="Log in using your @p.Caption account">@p.AuthenticationType</button>
|
||||
<button type="submit" class="btn btn-default" id="@p.AuthenticationScheme" name="provider" value="@p.AuthenticationScheme" title="Log in using your @p.Caption account">@p.AuthenticationScheme</button>
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
@using System.Security.Principal
|
||||
|
||||
@if (User.Identity.IsAuthenticated)
|
||||
@if (User.IsSignedIn())
|
||||
{
|
||||
//Either NTLM will be used or social authentication will be used. Based on the authentication schemes enabled remove an unused block.
|
||||
if (User.Identity.AuthenticationType != "NTLM")
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li>
|
||||
@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
|
||||
@Html.ActionLink("Hello " + User.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
|
||||
</li>
|
||||
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
|
||||
</ul>
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
//This code block necessary only for NTLM authentication
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li>
|
||||
<p class="nav navbar-text navbar-right">Hello, @User.Identity.GetUserName()!</p>
|
||||
<p class="nav navbar-text navbar-right">Hello, @User.GetUserName()!</p>
|
||||
</li>
|
||||
</ul>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,16 +15,16 @@
|
|||
"EntityFramework.SqlServer": "7.0.0-*",
|
||||
"EntityFramework.InMemory": "7.0.0-*", // For Mono.
|
||||
"Kestrel": "1.0.0-*",
|
||||
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
|
||||
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-*",
|
||||
"Microsoft.AspNet.Authentication.Google": "1.0.0-*",
|
||||
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-*",
|
||||
"Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-*",
|
||||
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-*",
|
||||
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
|
||||
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*",
|
||||
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-*",
|
||||
"Microsoft.AspNet.Mvc": "6.0.0-*",
|
||||
"Microsoft.AspNet.Security.Cookies": "1.0.0-*",
|
||||
"Microsoft.AspNet.Security.Facebook": "1.0.0-*",
|
||||
"Microsoft.AspNet.Security.Google": "1.0.0-*",
|
||||
"Microsoft.AspNet.Security.MicrosoftAccount": "1.0.0-*",
|
||||
"Microsoft.AspNet.Security.OpenIdConnect": "1.0.0-*",
|
||||
"Microsoft.AspNet.Security.Twitter": "1.0.0-*",
|
||||
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
|
||||
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
|
||||
"Microsoft.AspNet.Session": "1.0.0-*",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
using Microsoft.AspNet.Http.Security;
|
||||
using Microsoft.AspNet.Security;
|
||||
using Microsoft.AspNet.Http.Authentication;
|
||||
using Microsoft.AspNet.Authentication;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MusicStore.Mocks.Common
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ using System.Linq;
|
|||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Security.Facebook;
|
||||
using Microsoft.AspNet.Security.OAuth;
|
||||
using Microsoft.AspNet.Authentication.Facebook;
|
||||
using Microsoft.AspNet.Authentication.OAuth;
|
||||
using MusicStore.Mocks.Common;
|
||||
|
||||
namespace MusicStore.Mocks.Facebook
|
||||
|
|
@ -16,7 +16,7 @@ namespace MusicStore.Mocks.Facebook
|
|||
{
|
||||
internal static async Task OnAuthenticated(FacebookAuthenticatedContext context)
|
||||
{
|
||||
if (context.Identity != null)
|
||||
if (context.Principal != null)
|
||||
{
|
||||
Helpers.ThrowIfConditionFailed(() => context.AccessToken == "ValidAccessToken", "");
|
||||
Helpers.ThrowIfConditionFailed(() => context.Email == "AspnetvnextTest@test.com", "");
|
||||
|
|
@ -27,7 +27,7 @@ namespace MusicStore.Mocks.Facebook
|
|||
Helpers.ThrowIfConditionFailed(() => context.User.SelectToken("id").ToString() == context.Id, "");
|
||||
Helpers.ThrowIfConditionFailed(() => context.ExpiresIn.Value == TimeSpan.FromSeconds(100), "");
|
||||
Helpers.ThrowIfConditionFailed(() => context.AccessToken == "ValidAccessToken", "");
|
||||
context.Identity.AddClaim(new Claim("ManageStore", "false"));
|
||||
context.Principal.Identities.First().AddClaim(new Claim("ManageStore", "false"));
|
||||
}
|
||||
|
||||
await Task.FromResult(0);
|
||||
|
|
@ -35,14 +35,15 @@ namespace MusicStore.Mocks.Facebook
|
|||
|
||||
internal static async Task OnReturnEndpoint(OAuthReturnEndpointContext context)
|
||||
{
|
||||
if (context.Identity != null && context.SignInAsAuthenticationType == IdentityOptions.ExternalCookieAuthenticationType)
|
||||
if (context.Principal != null && context.SignInScheme == IdentityOptions.ExternalCookieAuthenticationScheme)
|
||||
{
|
||||
//This way we will know all notifications were fired.
|
||||
var manageStoreClaim = context.Identity.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault();
|
||||
var identity = context.Principal.Identities.First();
|
||||
var manageStoreClaim = identity?.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault();
|
||||
if (manageStoreClaim != null)
|
||||
{
|
||||
context.Identity.RemoveClaim(manageStoreClaim);
|
||||
context.Identity.AddClaim(new Claim("ManageStore", "Allowed"));
|
||||
identity.RemoveClaim(manageStoreClaim);
|
||||
identity.AddClaim(new Claim("ManageStore", "Allowed"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ using System.Linq;
|
|||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Security.Google;
|
||||
using Microsoft.AspNet.Security.OAuth;
|
||||
using Microsoft.AspNet.Authentication.Google;
|
||||
using Microsoft.AspNet.Authentication.OAuth;
|
||||
using MusicStore.Mocks.Common;
|
||||
|
||||
namespace MusicStore.Mocks.Google
|
||||
|
|
@ -16,7 +16,7 @@ namespace MusicStore.Mocks.Google
|
|||
{
|
||||
internal static async Task OnAuthenticated(GoogleAuthenticatedContext context)
|
||||
{
|
||||
if (context.Identity != null)
|
||||
if (context.Principal != null)
|
||||
{
|
||||
Helpers.ThrowIfConditionFailed(() => context.AccessToken == "ValidAccessToken", "Access token is not valid");
|
||||
Helpers.ThrowIfConditionFailed(() => context.RefreshToken == "ValidRefreshToken", "Refresh token is not valid");
|
||||
|
|
@ -26,7 +26,7 @@ namespace MusicStore.Mocks.Google
|
|||
Helpers.ThrowIfConditionFailed(() => context.Name == "AspnetvnextTest AspnetvnextTest", "Name is not valid");
|
||||
Helpers.ThrowIfConditionFailed(() => context.ExpiresIn.Value == TimeSpan.FromSeconds(1200), "ExpiresIn is not valid");
|
||||
Helpers.ThrowIfConditionFailed(() => context.User != null, "User object is not valid");
|
||||
context.Identity.AddClaim(new Claim("ManageStore", "false"));
|
||||
context.Principal.Identities.First().AddClaim(new Claim("ManageStore", "false"));
|
||||
}
|
||||
|
||||
await Task.FromResult(0);
|
||||
|
|
@ -34,14 +34,15 @@ namespace MusicStore.Mocks.Google
|
|||
|
||||
internal static async Task OnReturnEndpoint(OAuthReturnEndpointContext context)
|
||||
{
|
||||
if (context.Identity != null && context.SignInAsAuthenticationType == IdentityOptions.ExternalCookieAuthenticationType)
|
||||
if (context.Principal != null && context.SignInScheme == IdentityOptions.ExternalCookieAuthenticationScheme)
|
||||
{
|
||||
//This way we will know all notifications were fired.
|
||||
var manageStoreClaim = context.Identity.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault();
|
||||
var identity = context.Principal.Identities.First();
|
||||
var manageStoreClaim = identity?.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault();
|
||||
if (manageStoreClaim != null)
|
||||
{
|
||||
context.Identity.RemoveClaim(manageStoreClaim);
|
||||
context.Identity.AddClaim(new Claim("ManageStore", "Allowed"));
|
||||
identity.RemoveClaim(manageStoreClaim);
|
||||
identity.AddClaim(new Claim("ManageStore", "Allowed"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ using System.Linq;
|
|||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Security.MicrosoftAccount;
|
||||
using Microsoft.AspNet.Security.OAuth;
|
||||
using Microsoft.AspNet.Authentication.MicrosoftAccount;
|
||||
using Microsoft.AspNet.Authentication.OAuth;
|
||||
using MusicStore.Mocks.Common;
|
||||
|
||||
namespace MusicStore.Mocks.MicrosoftAccount
|
||||
|
|
@ -16,7 +16,7 @@ namespace MusicStore.Mocks.MicrosoftAccount
|
|||
{
|
||||
internal static async Task OnAuthenticated(MicrosoftAccountAuthenticatedContext context)
|
||||
{
|
||||
if (context.Identity != null)
|
||||
if (context.Principal != null)
|
||||
{
|
||||
Helpers.ThrowIfConditionFailed(() => context.AccessToken == "ValidAccessToken", "Access token is not valid");
|
||||
Helpers.ThrowIfConditionFailed(() => context.RefreshToken == "ValidRefreshToken", "Refresh token is not valid");
|
||||
|
|
@ -27,7 +27,7 @@ namespace MusicStore.Mocks.MicrosoftAccount
|
|||
Helpers.ThrowIfConditionFailed(() => context.ExpiresIn.Value == TimeSpan.FromSeconds(3600), "ExpiresIn is not valid");
|
||||
Helpers.ThrowIfConditionFailed(() => context.User != null, "User object is not valid");
|
||||
Helpers.ThrowIfConditionFailed(() => context.Id == context.User.SelectToken("id").ToString(), "User id is not valid");
|
||||
context.Identity.AddClaim(new Claim("ManageStore", "false"));
|
||||
context.Principal.Identities.First().AddClaim(new Claim("ManageStore", "false"));
|
||||
}
|
||||
|
||||
await Task.FromResult(0);
|
||||
|
|
@ -35,14 +35,15 @@ namespace MusicStore.Mocks.MicrosoftAccount
|
|||
|
||||
internal static async Task OnReturnEndpoint(OAuthReturnEndpointContext context)
|
||||
{
|
||||
if (context.Identity != null && context.SignInAsAuthenticationType == IdentityOptions.ExternalCookieAuthenticationType)
|
||||
if (context.Principal != null && context.SignInScheme == IdentityOptions.ExternalCookieAuthenticationScheme)
|
||||
{
|
||||
//This way we will know all notifications were fired.
|
||||
var manageStoreClaim = context.Identity.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault();
|
||||
var identity = context.Principal.Identities.First();
|
||||
var manageStoreClaim = identity?.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault();
|
||||
if (manageStoreClaim != null)
|
||||
{
|
||||
context.Identity.RemoveClaim(manageStoreClaim);
|
||||
context.Identity.AddClaim(new Claim("ManageStore", "Allowed"));
|
||||
identity.RemoveClaim(manageStoreClaim);
|
||||
identity.AddClaim(new Claim("ManageStore", "Allowed"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using Microsoft.AspNet.Security;
|
||||
using Microsoft.AspNet.Authentication;
|
||||
|
||||
namespace MusicStore.Mocks.OpenIdConnect
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Authentication.Notifications;
|
||||
using Microsoft.AspNet.Authentication.OpenIdConnect;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Security.Notifications;
|
||||
using Microsoft.AspNet.Security.OpenIdConnect;
|
||||
using Microsoft.IdentityModel.Protocols;
|
||||
using MusicStore.Mocks.Common;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.Authentication.OpenIdConnect;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Diagnostics;
|
||||
using Microsoft.AspNet.Diagnostics.Entity;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Security;
|
||||
using Microsoft.AspNet.Security.OpenIdConnect;
|
||||
using Microsoft.Framework.Cache.Memory;
|
||||
using Microsoft.Framework.ConfigurationModel;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
|
@ -71,7 +71,7 @@ namespace MusicStore
|
|||
// Configure Auth
|
||||
services.Configure<AuthorizationOptions>(options =>
|
||||
{
|
||||
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("ManageStore", "Allowed").Build());
|
||||
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Authentication.Facebook;
|
||||
using Microsoft.AspNet.Authentication.Google;
|
||||
using Microsoft.AspNet.Authentication.MicrosoftAccount;
|
||||
using Microsoft.AspNet.Authentication.Twitter;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Diagnostics;
|
||||
using Microsoft.AspNet.Diagnostics.Entity;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Security;
|
||||
using Microsoft.AspNet.Security.Facebook;
|
||||
using Microsoft.AspNet.Security.Google;
|
||||
using Microsoft.AspNet.Security.MicrosoftAccount;
|
||||
using Microsoft.AspNet.Security.Twitter;
|
||||
using Microsoft.Framework.Cache.Memory;
|
||||
using Microsoft.Framework.ConfigurationModel;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
|
@ -107,7 +107,7 @@ namespace MusicStore
|
|||
// Configure Auth
|
||||
services.Configure<AuthorizationOptions>(options =>
|
||||
{
|
||||
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("ManageStore", "Allowed").Build());
|
||||
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
using Microsoft.AspNet.Security;
|
||||
using Microsoft.AspNet.Security.Twitter.Messages;
|
||||
using Microsoft.AspNet.Authentication;
|
||||
using Microsoft.AspNet.Authentication.Twitter.Messages;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MusicStore.Mocks.Twitter
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Authentication.Twitter;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Security.Twitter;
|
||||
using MusicStore.Mocks.Common;
|
||||
|
||||
namespace MusicStore.Mocks.Twitter
|
||||
|
|
@ -14,13 +14,13 @@ namespace MusicStore.Mocks.Twitter
|
|||
{
|
||||
internal static async Task OnAuthenticated(TwitterAuthenticatedContext context)
|
||||
{
|
||||
if (context.Identity != null)
|
||||
if (context.Principal != null)
|
||||
{
|
||||
Helpers.ThrowIfConditionFailed(() => context.UserId == "valid_user_id", "UserId is not valid");
|
||||
Helpers.ThrowIfConditionFailed(() => context.ScreenName == "valid_screen_name", "ScreenName is not valid");
|
||||
Helpers.ThrowIfConditionFailed(() => context.AccessToken == "valid_oauth_token", "AccessToken is not valid");
|
||||
Helpers.ThrowIfConditionFailed(() => context.AccessTokenSecret == "valid_oauth_token_secret", "AccessTokenSecret is not valid");
|
||||
context.Identity.AddClaim(new Claim("ManageStore", "false"));
|
||||
context.Principal.Identities.First().AddClaim(new Claim("ManageStore", "false"));
|
||||
}
|
||||
|
||||
await Task.FromResult(0);
|
||||
|
|
@ -28,14 +28,15 @@ namespace MusicStore.Mocks.Twitter
|
|||
|
||||
internal static async Task OnReturnEndpoint(TwitterReturnEndpointContext context)
|
||||
{
|
||||
if (context.Identity != null && context.SignInAsAuthenticationType == IdentityOptions.ExternalCookieAuthenticationType)
|
||||
if (context.Principal != null && context.SignInScheme == IdentityOptions.ExternalCookieAuthenticationScheme)
|
||||
{
|
||||
//This way we will know all notifications were fired.
|
||||
var manageStoreClaim = context.Identity.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault();
|
||||
var identity = context.Principal.Identities.First();
|
||||
var manageStoreClaim = identity?.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault();
|
||||
if (manageStoreClaim != null)
|
||||
{
|
||||
context.Identity.RemoveClaim(manageStoreClaim);
|
||||
context.Identity.AddClaim(new Claim("ManageStore", "Allowed"));
|
||||
identity.RemoveClaim(manageStoreClaim);
|
||||
identity.AddClaim(new Claim("ManageStore", "Allowed"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue