Code Monkey home page Code Monkey logo

lua-resty-keycloak's Introduction

lua-resty-keycloak

lua-resty-keycloak is a Keycloak adaptar for OpenResty.

It provide OpenID Connect Resource Server functinality with keycloak IdP server.

Open ID connect

It can verify ID Token from client using lua-resty-odic.

Authorization Service

It can support the Authorization Service provided by Keycloak. This function provides fine graind access controlle and integrate access policy to the keycloak server.

NOTE: The Authoriztion Service function is limited compared with the adapter provided by Keycloak. Only provides url based access contorl.

##Author Takashi Mogi, Hitachi,Ltd

Installation

TBD

Usage

  local Authz = require "resty.keycloak.authz"
  local Oidc = require "resty.keycloak.oidc"

  local access_token,err = get_bearer_token() 
  
  if access_token == nil then 
    ngx.status = 403
    ngx.say(err)
    ngx.exit(ngx.HTTP_FORBIDDEN)
  end

  local opt = {
    keycloak_uri = "http://keycloak.example.com/auth/realms/example/",
    client_id = "client",
    client_secret = "client_secret"
  }
  
  -- validate access token 
  local oidc = Oidc:new(opt)
  local res, err  = oidc:validate_token(access_token)
  
  if err then
    ngx.status=403
    ngx.say(err)
    ngx.exit(ngx.HTTP_FORBIDDEN)
  end

  local authz = Authz:new(opt)
  authz:initialize()

  -- check permissions using resource set provided by keycloak server
  if not authz:is_authorize(access_token, ngx.var.uri) then
    ngx.status = 403
    ngx.exit(ngx.HTTP_FORBIDDEN)
  end

TODO

  • Common
    • improve error handling and logging
    • test cases
    • use caches
  • Authorization service
    • "Authorization Scopes" and "Methods" based access control.
    • improve path matchings between request path and resources.
      • Wildcards: /*
      • Suffix: /*.html
      • Sub-paths: /path/*
      • Path parameters: /resource/{id}
      • Exact match: /resource
      • Patterns: /{version}/resource, /api/{version}/resource, /api/{version}/resource/*

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.