cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP Cloud SDK for JavaScript: Error integrating XSSEC with NestJS

former_member231229
Participant
0 Likes
2,341

Hello all,
following what ttrapp and dhem were discussing here I did some research about how to (within my best effort and skills) integrate the usage of JWTStrategy from xssec library into the Passport implementation of NestJS, which is what we get when initializing a new project using the Sap Cloud SDK CLI.

I "almost" got there, but I am now stuck in an issue which I really cannot resolve.

I created a simple repository sapcloudsdk-nestjs-xsuaa to replicate the issue, but here's briefly what I did:

  1. Prepare XSUAA instance and Destination instance on CF
  2. Add the approuter to the project (using CLI's add approuter command)
  3. Properly configure default-env.json files, both in the approuter folder and in the root folder for local testing
  4. Install necessary dependencies: @nestjs/passport passport passport-jwt @sap/xssec @sap/xsenv

Generate a new "auth" module, the custom strategy class and a custom guard to protect endpoints:

  1. nest generate module auth/auth

  2. nest generate class auth/xsuaa.strategy
  3. nest generate guard auth/xsuaa.guard

The setup compiles and the application starts. Assuming that you are using default ports, calling http://localhost:5000/yourendpoint lands to the XSUAA login page.

Do the login and:

[Nest] 17174   - 2020-03-15 21:48:43   [ExceptionsHandler] this._secretOrKeyProvider is not a function +15597ms
TypeError: this._secretOrKeyProvider is not a function
    at XsuaaStrategy.JwtStrategy.authenticate (/Users/stevebob/Desktop/SAP/CLOUD SDK/xsuua-test/node_modules/passport-jwt/lib/strategy.js:99:10)
    at attempt (/Users/stevebob/Desktop/SAP/CLOUD SDK/xsuua-test/node_modules/passport/lib/middleware/authenticate.js:366:16)
    at authenticate (/Users/stevebob/Desktop/SAP/CLOUD SDK/xsuua-test/node_modules/passport/lib/middleware/authenticate.js:367:7)
    at Promise (/Users/stevebob/Desktop/SAP/CLOUD SDK/xsuua-test/node_modules/@nestjs/passport/dist/auth.guard.js:84:3)
    at new Promise (<anonymous>)
    at /Users/stevebob/Desktop/SAP/CLOUD SDK/xsuua-test/node_modules/@nestjs/passport/dist/auth.guard.js:76:83
    at XsuaaGuard.<anonymous> (/Users/stevebob/Desktop/SAP/CLOUD SDK/xsuua-test/node_modules/@nestjs/passport/dist/auth.guard.js:48:36)
    at Generator.next (<anonymous>)
    at /Users/stevebob/Desktop/SAP/CLOUD SDK/xsuua-test/node_modules/@nestjs/passport/dist/auth.guard.js:20:71
    at new Promise (<anonymous>)

I think it is related on how the strategy is being configured: the "secretOrKeyProvider" parameter expect a callback function (and not a new JWTStrategy instance)

If anyone has an idea, I'll be happy to contribute - and learn 🙂

Thanks a lot,

Roberto.

Accepted Solutions (0)

Answers (0)