Skip to content

Unofficial Permify client implementation for AspNetCore projects

License

Notifications You must be signed in to change notification settings

luco5826/Permify.AspNetCore

Repository files navigation

Permify.AspNetCore

This is an unofficial implementation of the Permify authorization service to be used in Asp.NET Core applications

Installation

This package is available as a NuGet package and can be added to your project through the command

dotnet add package Permify.AspNetCore

Usage

// Program.cs
using Permify.AspNetCore.Extensions;

builder.Services.AddPermify(opts =>
{
    opts.Host = "http://localhost:3478";
});

// From now on, the IPermifyAuthorizationService singleton is available for DI


// MyController.cs
[HttpGet]
public Task<ActionResult> GetData()
{
    bool isUserAllowed = await _authorizationService.Can
    (
        // Extract from the HTTP request
        new Subject("1", "user"), 

        // Depending on the action this request is representing
        "get_data",

        // Extracted from request parameters
        new Entity("10", "datarepo")
    );

    if (!isUserAllowed)
    {
        return await Task.FromResult(Forbid());
    }

    // User is allowed...
}

Build instructions

This project has been built with the following tools:

Once all the tools have been installed, clone the repository, generate the protobuf files following the .proto files specifications and build the project

git clone https://github.com/luco5826/Permify.AspNetCore.git
cd Permify.AspNetCore/src/Permify.AspNetCore/Protos
buf generate --include-imports
cd ..
dotnet build

About

Unofficial Permify client implementation for AspNetCore projects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages