Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Nov 3, 2023
1 parent 87161bd commit 874b3f0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
37 changes: 32 additions & 5 deletions src/routes/oauth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ export const oauthProviders = Router()
*
* The redirect url has been set in the previous middleware and is available in the locals
*/
.all(`${OAUTH_ROUTE}/:provider`, ({ headers: { host }, params: { provider } }, res, next) => {
.all(`${OAUTH_ROUTE}/:provider`, ({ protocol, path, headers: { host }, params: { provider } }, res, next) => {
const redirectTo: string = res.locals.redirectTo;
const providerConfig = grantConfig[provider];
const providerConfig = createGrantConfig()[provider];
// * Check if provider is enabled
if (!providerConfig) {
logger.warn(`Provider "${provider}" is not enabled`);
Expand All @@ -115,9 +115,11 @@ export const oauthProviders = Router()
);
}

if ( host ) {
providerConfig.origin = host.split("/signin")[0];
}
// const prefix = path.split('/signin')[0];
// console.log('path, prefix: ', path, prefix);
// res.locals.grant = {dynamic: {
// origin: `${protocol}://${host}/v1${prefix}`},
// };

next();
})
Expand Down Expand Up @@ -152,7 +154,32 @@ export const oauthProviders = Router()
* Grant middleware: handle the oauth flow until the callback
* @see {@link file://./config/index.ts}
*/
// .all(`${OAUTH_ROUTE}/:provider/callback`, async ({ protocol, headers, }, res) => {
// res.locals.grant = {dynamic: {
// origin: `${protocol}://${headers.host}/v1`},
// };

// })
.use((req, res, next) => {
// put here code before grant.express
// const prefix = path.split('/signin')[0];
console.log(123);
// const prefix = path.split('/signin')[0];
// console.log('path, prefix: ', path, prefix);
res.locals.grant = {dynamic: {
origin: `${req.protocol}://${req.headers.host}/v1`},
};
next();

})
.use(grant.express(grantConfig))
// .use((req, _, next) => {
// // put here code before grant.express
// // const prefix = path.split('/signin')[0];
// console.log(123);
// grant.express(createGrantConfig(`${req.protocol}://${req.headers.host}/v1`));
// next();
// })

/**
* The following middleware is reached in the Oauth Callback:
Expand Down
2 changes: 1 addition & 1 deletion src/routes/oauth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const createGrantConfig = (): GrantConfig =>
},
{
defaults: {
origin: ENV.AUTH_SERVER_URL,
// origin: ENV.AUTH_SERVER_URL,
prefix: OAUTH_ROUTE,
transport: 'session',
scope: ['email', 'profile'],
Expand Down

0 comments on commit 874b3f0

Please sign in to comment.