-
Hi all! I've been trying to make v6 work with Fastify Passport without success. Codeimport fastifyPassport, { type Strategy } from "@fastify/passport";
import { fastify } from "fastify";
import { discovery } from "openid-client";
import { Strategy as OpenidStrategy } from "openid-client/passport";
const client = await discovery(
new URL(config.openId.issuer),
config.openId.clientId,
config.openId.clientSecret,
);
const strategy = new OpenidStrategy(
{
callbackURL: config.openId.callbackUri,
config: client,
scope: "openid",
},
(token, callback) => {
// No matter, execution never arrives here
callback(null);
},
);
strategy.currentUrl = function () {
return new URL(config.openId.callbackUri);
};
// Type-cast `passport.Strategy` to `fastify-passport.Strategy`
const openidStrategy = strategy as unknown as Strategy;
const app = fastify()
.register(fastifyPassport.initialize())
.register(fastifyPassport.secureSession())
.get("/auth/connect/openid", fastifyPassport.authenticate(openidStrategy))
.get(
"/auth/connect/openid/callback",
fastifyPassport.authenticate(openidStrategy, {
failureRedirect: "/unauthorized",
successRedirect: "/",
}),
); The conversion was quite fine but but now I can't get it to work. IssueCurrently it goes into an infinite redirection loop from Potential issueI used to have this config Not an issueThe need to overwrite Worth mentioning
ClosingIf anyone else is using a similar setup and managed to make it work do spill the beans. Otherwise I'll probably wait for Fastify Passport to update their integrations tests and see if that helps me :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
currentUrl is not the same as your callbackUrl which is what you're currently overloading with. It's meant to return the current url incl. the query component to which the AS returned the end-user. |
Beta Was this translation helpful? Give feedback.
currentUrl is not the same as your callbackUrl which is what you're currently overloading with. It's meant to return the current url incl. the query component to which the AS returned the end-user.