Skip to content

Commit

Permalink
trying to add strategy to passport
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilamb committed Jan 23, 2024
1 parent ff59556 commit 6283c48
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions backend/src/config/auth.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,29 @@ export default registerAs('authConfig', () => {
});

const oauth2s = oauth2Names.map((oauth2Name) => {
const strategy = new OAuth2Strategy(
{
authorizationURL: process.env[`HD_AUTH_OAUTH2_${oauth2Name}_AUTHORIZATION_URL`],
tokenURL: process.env[`HD_AUTH_OAUTH2_${oauth2Name}_TOKEN_URL`],
clientID: process.env[`HD_AUTH_OAUTH2_${oauth2Name}_CLIENT_ID`],
clientSecret: process.env[`HD_AUTH_OAUTH2_${oauth2Name}_CLIENT_SECRET`],
callbackURL: 'http://localhost:3000/auth/example/callback', // Modify as needed
},
function (accessToken, refreshToken, profile, cb) {
// Your logic for handling user profile and callback
User.findOrCreate({ exampleId: profile.id }, function (err, user) {
return cb(err, user);
});
}
);

// Check for https_proxy environment variable and set proxy agent if present
const HttpsProxyAgent = require('https-proxy-agent');
if (process.env['https_proxy']) {
const httpsProxyAgent = new HttpsProxyAgent(process.env['https_proxy']);
strategy._oauth2.setAgent(httpsProxyAgent);
}

return {
identifier: oauth2Name,
providerName: process.env[`HD_AUTH_OAUTH2_${oauth2Name}_PROVIDER_NAME`],
Expand Down

0 comments on commit 6283c48

Please sign in to comment.