This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Authorization.Infrastructure; | |
namespace Formum.Api.Authorization.Operations | |
{ | |
public class PostOperations | |
{ | |
public static OperationAuthorizationRequirement Delete = new OperationAuthorizationRequirement { Name = "PostDelete" }; | |
public static OperationAuthorizationRequirement Edit = new OperationAuthorizationRequirement { Name = "PostEdit" }; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Forum.Models | |
{ | |
public class Post | |
{ | |
public Guid Id { get; private set; } | |
public Guid UserId { get; private set; } | |
public DateTime CreatedAt { get; private set; } | |
public string Text { get; private set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
[Trait("Category", Category)] | |
public async void HandleEdit_WhenCalledWithResourceOwner_ShouldSucceed() | |
{ | |
var resource = make_PostDefault(); | |
var authorizationModel = PostAuthorizationModel.From(resource); | |
var user = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim> { new Claim("sub", UserIdDefault.ToString()) })); | |
var requirement = PostOperations.Edit; | |
var authorizationContext = new AuthorizationHandlerContext(new List<IAuthorizationRequirement> { requirement }, user, authorizationModel); | |
var authorizationHandler = new PostAuthorizationHandler(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Forum.Interfaces; | |
using System; | |
using System.Threading.Tasks; | |
using Formum.Api.Authorization.Models; | |
using Formum.Api.Authorization.Operations; | |
using Forum.Models; | |
using Microsoft.AspNetCore.Authorization; | |
using Microsoft.AspNetCore.Mvc; | |
namespace Forum.Api.Controllers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class WebSockets | |
{ | |
public static void Main(string[] args) | |
{ | |
RunWebSockets().GetAwaiter().GetResult(); | |
} | |
private static async Task RunWebSockets() | |
{ | |
var ws = new ClientWebSocket(); //------v please use a fresh token to test out this is just a PoC client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomAdapter : DefaultEventAdapter | |
{ | |
protected override byte[] ToBytes(object @event, JObject metadata, out string type, out bool isJson) | |
{ | |
var bytes = base.ToBytes(@event, metadata, out type, out isJson); | |
//Add some additional metadata: | |
metadata["additionalProp"] = true; |
OlderNewer