GithubHelp home page GithubHelp logo

xteron / be.auto.servicestack.authentication.keycloak Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kingeser/be.auto.servicestack.authentication.keycloak

0.0 0.0 0.0 31 KB

Servicestack Keycloak Role Based Authentication

JavaScript 1.28% C# 89.75% TypeScript 1.66% HTML 7.31%

be.auto.servicestack.authentication.keycloak's Introduction

Be.Auto.Servicestack.Authentication.Keycloak

Servicestack Keycloak Role Based Authentication

This project demonstrates how to implement Keycloak role-based authentication in a ServiceStack application. The authentication is achieved using the KeycloakCredentialsAuthProvider and KeycloakOAuthProvider provided by the ServiceStack framework.

Usage

var authFeature = new AuthFeature(() => new AuthUserSession(), new IAuthProvider[]
{
    new KeycloakCredentialsAuthProvider(AppSettings)
        .MapClaim(t => t.Roles, "role")
        .MapClaim(t => t.Permissions, "groups"),
    new KeycloakOAuthProvider(AppSettings)
        .MapClaim(t => t.Roles, "role")
        .MapClaim(t => t.Permissions, "groups")
});

Plugins.Add(authFeature);

if (HostingEnvironment.IsDevelopment())
{
    authFeature.MigrateKeycloakRoles(AppSettings);
}

KeycloakRequiredRole Attribute The KeycloakRequiredRole attribute is used to automatically validate the presence of a specific role in the request. Apply this attribute to the ServiceStack services or methods that require certain roles for access.

[KeycloakRequiredRole]
public class ProductService : Service
{
    public object Any(SaveProduct request)
    {
        return new ProductResponse
        {
            Result = request.Name
        };
    }

    public object Any(FindProduct request)
    {
        return new ProductResponse
        {
            Result = request.Name
        };
    }
}

Migration of Keycloak Roles During development, you can use the MigrateKeycloakRoles method to migrate Keycloak roles to your ServiceStack application. This ensures that your roles are synchronized with the Keycloak server.

if (HostingEnvironment.IsDevelopment())
{
    authFeature.MigrateKeycloakRoles(AppSettings);
}

be.auto.servicestack.authentication.keycloak's People

Contributors

kingeser avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.