GithubHelp home page GithubHelp logo

rafaelcascalho / keycloak-middleware-ts Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 1.0 582 KB

Keycloakd middleware to simply use keycloak validation and verifications.

License: MIT License

JavaScript 0.44% TypeScript 99.56%

keycloak-middleware-ts's People

Contributors

dependabot[bot] avatar hebertcisco avatar rafaelcascalho avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

lloydnas

keycloak-middleware-ts's Issues

createKeycloakCtx() - TypeError: this.request.post is not a function

When trying to inject an axios configuration in the request parameter in the createKeycloakCtx function, a typing error is returned, saying that the post method is not a function, as in the example below...

Steps to reproduce the behavior:

  1. Configure the project as explained in README.md under Usage.
  2. Add axios configuration following AxiosInstance typing
  3. Use the create user method
  4. See error

Will return a typing error showing that the post is not a function

Example:

[Nest] 16436  - 17/02/2022 16:35:44   ERROR [UserService] TypeError: this.request.post is not a function
TypeError: this.request.post is not a function
    at AccessToken.<anonymous> (C:\Users\example\www\nestjs-project\node_modules\keycloak-middleware-ts\lib\AccessToken.js:69:49)
    at Generator.next (<anonymous>)
    at C:\Users\example\www\nestjs-project\node_modules\keycloak-middleware-ts\lib\AccessToken.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (C:\Users\example\www\nestjs-project\node_modules\keycloak-middleware-ts\lib\AccessToken.js:4:12)
    at AccessToken.get (C:\Users\example\www\nestjs-project\node_modules\keycloak-middleware-ts\lib\AccessToken.js:55:16)
    at UserManager.<anonymous> (C:\Users\example\www\nestjs-project\node_modules\keycloak-middleware-ts\lib\UserManager.js:83:50)
    at Generator.next (<anonymous>)
    at C:\Users\example\www\nestjs-project\node_modules\keycloak-middleware-ts\lib\UserManager.js:8:71
    at new Promise (<anonymous>)

Versions:

  • OS: Windows NT
  • Node 16.13.1
  • NPM 8.2.0

Additional context
Below is an example of configuration and use of the library where this problem occurs

Configuration

import createKeycloakCtx from 'keycloak-middleware-ts';
import dotenv from 'dotenv';
import qs from 'qs';

dotenv.config();

export const {
  KEYCLOAK_REALM,
  KEYCLOAK_URL,
  KEYCLOAK_CLIENT_ID,
  KEYCLOAK_CLIENT_SECRET,
  KEYCLOAK_USERNAME,
  KEYCLOAK_PASSWORD,
  KEYCLOAK_JWT_KEY,
} = process.env;

const axiosConfig = {
  config: {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify({
      grant_type: 'password',
      clientId: KEYCLOAK_CLIENT_ID,
      clientSecret: KEYCLOAK_CLIENT_SECRET,
      username: KEYCLOAK_USERNAME,
      password: KEYCLOAK_PASSWORD,
    }),
  },
};
export const keycloak = createKeycloakCtx(
  {
    realm: KEYCLOAK_REALM,
    authServerUrl: KEYCLOAK_URL,
    clientId: KEYCLOAK_CLIENT_ID,
    clientSecret: KEYCLOAK_CLIENT_SECRET,
    username: KEYCLOAK_USERNAME,
    password: KEYCLOAK_PASSWORD,
    jwtKey: KEYCLOAK_JWT_KEY,
    jwtKeyAlgorithms: ['RS256'],
  },
  axiosConfig,
);

Usage

await keycloak.users
                    .create({
                      firstName: 'John',
                      lastName: 'Doe',
                      username: 'john_doe',
                      email: '[email protected]',
                      enabled: true,
                      password: 'str0ng-p4ss',
});

In the documentation, the installation instruction is not right

Issue

In the documentation, the installation instruction is not right

In the document README.md it shows the instruction to install the library, but it is not published like this in NPM.

npm install -S keycloak-backend-ts

To Reproduce
Steps to reproduce the behavior:

  1. Go to '/README.md'
  2. See installation instruction

What to do?
Just change the package name according to what was published in NPM

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.