Coder Social home page Coder Social logo

adamboutcher / keycloak-conditional-authenticators Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jdelker/keycloak-conditional-authenticators

0.0 0.0 0.0 20 KB

Keycloak Authenticator to be used as a condition for matching against request headers

License: Apache License 2.0

Java 100.00%

keycloak-conditional-authenticators's Introduction

keycloak-conditional-authenticators

Additional Conditional Keycloak Authenticator modules to be used in the authentication flow

When it comes to conditional authentication in a keycloak authentication flow, there are very little options available. Beginning with Keycloak 10, support for conditional flow executions have been added, that allow a much more flexible way to define conditions for existing authentication modules. Multiple Condition Modules can now be combined together in a sub-flow to define a logical AND condition. Unfortunately, there are not very many of those modules available (at least up to Keycloak 11) to get a useful scenario out of that.

This project shall serve as a container for additional Conditional Modules. Currently contained:

  • ConditionalHeaderAuthenticator: Matches the request HTTP headers against a given expression

Build

To build the JAR module, invoke

mvn package

This will download all required dependencies and build the JAR in the target directory.

Installation

  1. Create a new directory providers in your Keycloak installation dir (if not already existing).
  2. Restart keycloak

All authenticators provided by this module are then available in the authentication flow configuration.

Usage example

A requirement (which actually led to development of this module) was to perform a somewhat more complex - but actually quite common - conditional OTP authentication. That is: A user shall be required to perform a multi-factor authentication (password + OTP), when he is a privileged user (= has particular keycloak role) and is located externally (= has foreign IP address).

There is already a "Conditional OTP Form" available in keycloak, but it fails on the required AND-condition. Since Keycloak 10, the authentication flow is now capable of combining multiple conditional authenticators to trigger the requirement of a particular authentication module. However, there is simply no conditional module available to match the request headers. This is where this module(s) come into play.

With that, the final authentication sub-flow for performing the conditional password + OTP authentication looks like this:

  • Sub-Flow: "Conditional OTP Flow" (Type: Flow; Requirement: Conditional)
    • Execution: "Condition - User Configured" (Type: Authenticator.Conditional; Requirement: Required)
    • Execution: "Condition - User Role" (Type: Authenticator.Conditional; Requirement: Required; Configuration: User Role = xyz)
    • Execution: "Condition - Request Headers" (Type: Authenticator.Conditional; Requirement: Required; Configuration: )
    • Execution: "OTP Form" (Type: Authenticator; Requirement: Required)

Configuration for "Condition - User Role":

  • User Role = xyz

Configuration for "Condition - Request Headers":

  • Required Header Expression = X-Forwarded-For: (10.8.|192.168.)
  • Expression Inversion = True

Release History

  • 1.0
    • Initial release.
    • Added ConditionalHeaderAuthenticator

Contributing

  1. Fork it (https://github.com/jdelker/keycloak-conditional-authenticator/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

keycloak-conditional-authenticators's People

Contributors

adamboutcher avatar dependabot[bot] avatar jdelker 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.