mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Don't return empty array for no oauth providers
This commit is contained in:
@@ -204,33 +204,39 @@ router.post(
|
||||
})
|
||||
);
|
||||
|
||||
router.get('/oauth', asyncHandler(async (req, res, next) => {
|
||||
const providers = env.OAUTH_PROVIDERS.split(',');
|
||||
res.locals.payload = { data: providers };
|
||||
return next();
|
||||
}));
|
||||
router.get(
|
||||
'/oauth',
|
||||
asyncHandler(async (req, res, next) => {
|
||||
const providers = env.OAUTH_PROVIDERS.split(',').filter((p: string) => p);
|
||||
res.locals.payload = { data: providers.length > 0 ? providers : null };
|
||||
return next();
|
||||
})
|
||||
);
|
||||
|
||||
router.use(
|
||||
'/oauth',
|
||||
session({ secret: env.SECRET as string, saveUninitialized: false, resave: false })
|
||||
);
|
||||
|
||||
router.get('/oauth/:provider', asyncHandler(async(req, res, next) => {
|
||||
const config = { ...grantConfig };
|
||||
delete config.defaults;
|
||||
router.get(
|
||||
'/oauth/:provider',
|
||||
asyncHandler(async (req, res, next) => {
|
||||
const config = { ...grantConfig };
|
||||
delete config.defaults;
|
||||
|
||||
const availableProviders = Object.keys(config);
|
||||
const availableProviders = Object.keys(config);
|
||||
|
||||
if (availableProviders.includes(req.params.provider) === false) {
|
||||
throw new RouteNotFoundException(`/auth/oauth/${req.params.provider}`);
|
||||
}
|
||||
if (availableProviders.includes(req.params.provider) === false) {
|
||||
throw new RouteNotFoundException(`/auth/oauth/${req.params.provider}`);
|
||||
}
|
||||
|
||||
if (req.query?.redirect && req.session) {
|
||||
req.session.redirect = req.query.redirect;
|
||||
}
|
||||
if (req.query?.redirect && req.session) {
|
||||
req.session.redirect = req.query.redirect;
|
||||
}
|
||||
|
||||
next();
|
||||
}));
|
||||
next();
|
||||
})
|
||||
);
|
||||
|
||||
router.use(grant.express()(grantConfig));
|
||||
|
||||
@@ -249,11 +255,16 @@ router.get(
|
||||
accountability: accountability,
|
||||
});
|
||||
|
||||
const email = getEmailFromProfile(req.params.provider, req.session!.grant.response?.profile);
|
||||
const email = getEmailFromProfile(
|
||||
req.params.provider,
|
||||
req.session!.grant.response?.profile
|
||||
);
|
||||
|
||||
req.session?.destroy(() => { });
|
||||
req.session?.destroy(() => {});
|
||||
|
||||
const { accessToken, refreshToken, expires } = await authenticationService.authenticate({ email });
|
||||
const { accessToken, refreshToken, expires } = await authenticationService.authenticate({
|
||||
email,
|
||||
});
|
||||
|
||||
if (redirect) {
|
||||
res.cookie('directus_refresh_token', refreshToken, {
|
||||
|
||||
Reference in New Issue
Block a user