Skip to content

huysentruitw/owin-action-middleware

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OWIN Action Middleware

Build status

OWIN middleware that allows sending actions to a single page application in the form of a cookie or redirect.

When the middleware is challenged, it will redirect to a fixed URL passing an action object in the URL or return an JavaScript readable cookie containing an action object as JSON.

This is useful in cases where the back-end requests a single-page application to perform a certain action without having to hardcode different front-end routes.

F.e. when sending out notification e-mails, you sometimes want to include back-end links in the e-mail.

Get it on NuGet

PM> Install-Package OwinActionMiddleware
PM> Install-Package OwinActionMiddleware.WebApi

Usage

The base package contains an extension method to be used on the IOwinContext interface, while the WebApi package adds an extension method to be used in an ApiController.

From OWIN middleware

app.Use(async (ctx, next) =>
{
    if (ctx.Request.Path != new PathString("/test")) await next();
    ctx.ChallengeActionMiddleware(new ActionData { Action = "JumpAround" });
    ctx.Response.StatusCode = (int)HttpStatusCode.OK;
});

From WebApi controller

[RoutePrefix("navigate")]
public class MyApiController : ApiController
{
    [HttpGet, Route("userprofile")]
    public IHttpActionResult Action(Guid userId)
    {
        return this.Action(new OpenUserProfileAction(userId));
    }
}

public class OpenUserProfileAction : Action
{
    public OpenUserProfileAction(Guid userId)
    {
        Action = "OpenUserProfile";
        UserId = userId;
    }

    public Guid UserId { get; }
}

About

OWIN middleware that allows sending actions to a single page application in the form of a cookie

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%