kong with keycloak Authorization based on scope

i am looking forward to restricting user access based on scope. i am using Kong API gateway here is my docker file used for adding nokia-oidc plugin.

docker file :

FROM kong:latest  
USER root
RUN apk update && apk add git unzip luarocks
RUN luarocks install kong-oidc  
USER kong

in token, i am getting scope like "openid profile email"

"session_state": "8d408ace-4692-458c-a7d0-69b19c1ded11",
  "acr": "0",
  "allowed-origins": [
  "scope": "openid profile email",

i am looking how restrict used based on scope exist or not as openid is default one.


it's not working as expected. if myscope not exist in token still i am able to login.

please help thanks in advance...!


  • With OIDC plugin you won't be able to perform authentication however you can do authorization

    You have to use plugin :

    Which will parse JWT token from internal header x-access-token and based on you can authenticate user via scope, realm role and client roles.

    Use this docker to add plugin inside Kong

    FROM kong:2.0.3-alpine
    LABEL description="Alpine + Kong 2.0.3 + kong-oidc plugin"
    USER root
    RUN apk update && apk add git unzip luarocks
    RUN luarocks install kong-oidc
    RUN git clone \
        && cd kong-oidc \
        && luarocks make
    RUN luarocks pack kong-oidc ${OIDC_PLUGIN_VERSION} \
         && luarocks install kong-oidc-${OIDC_PLUGIN_VERSION}.all.rock
    RUN git clone --branch 20200505-access-token-processing \
        && cd kong-plugin-jwt-keycloak \
        && luarocks make
    RUN luarocks pack kong-plugin-jwt-keycloak ${JWT_PLUGIN_VERSION} \
         && luarocks install kong-plugin-jwt-keycloak-${JWT_PLUGIN_VERSION}.all.rock
    USER kong

    you might also have to change JWT-Keyclaok plugin priority to 900 or less to start execution after OIDC plugin.