cancel
Showing results for 
Search instead for 
Did you mean: 

@sap/xssec and Nest.JS

detrapto
Explorer
0 Kudos

Hey,

I'm wondering if there are any examples available showing how to make use of @sap/xssec (especially the included JwtStrategy) within a Nest.JS project, since this is what you get (and want) when starting a new project with the sap-cloud-sdk CLI...

Accepted Solutions (1)

Accepted Solutions (1)

dhem
Active Participant

Hi Tobias,

currently we don't have any more advanced tutorials with Nest.js than our getting started series. However, Nest.js by default uses Express.js under the hood. Here's an example showing how to use the JWTStrategy with Passport (which is a middleware package for Express.js):

var express = require('express');
var passport = require('passport');
var JWTStrategy = require('@sap/xssec').JWTStrategy;
var xsenv = require('@sap/xsenv');

...

var app = express();

...

passport.use(new JWTStrategy(xsenv.getServices({uaa:{tag:'xsuaa'}}).uaa));

app.use(passport.initialize());
app.use(passport.authenticate('JWT', { session: false }));

Based on this, the Nest.js documentation on middleware should hopefully provide you with the means to integrate this into your project.

Hope that helps!

Best regards,
Dennis

detrapto
Explorer

Hi Dennis,

I am already using those express middlewares as global middlewares within my nest app, which works pretty good so far.

I just thought there might be some examples on how to wrap that into Nest.JS Guards to be more flexible. I think, I will come back to that idea when having digged a little deeper into nest...

Thanks a lot for your support!

dhem
Active Participant

You're welcome! If you build something that you think is worth sharing, I'd be happy to take a look at it!

Answers (0)