mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: login to google success
This commit is contained in:
1 parent
7fb0a22786
commit
44b3304046
8 files changed
+62
-5
No files matched your search
@@ -26,4 +26,14 @@ router.get('/check-username', checkUsername)
|
||||
|
||||
router.get('/check-session', checkSession)
|
||||
|
||||
router.get('/google', passport.authenticate('google'))
|
||||
|
||||
router.get(
|
||||
'/google/callback',
|
||||
passport.authenticate('google', {
|
||||
successRedirect: '/',
|
||||
failureRedirect: '/login',
|
||||
})
|
||||
)
|
||||
|
||||
export default router
|
||||
@@ -0,0 +1,18 @@
|
||||
import GoogleStrategy from 'passport-google-oidc'
|
||||
|
||||
import config from '../config.js'
|
||||
|
||||
console.log('Google config:', config.google)
|
||||
|
||||
export default new GoogleStrategy(
|
||||
{
|
||||
clientID: config.google.clientID,
|
||||
clientSecret: config.google.clientSecret,
|
||||
callbackURL: '/api/v1/auth/google/callback',
|
||||
scope: ['profile', 'email'],
|
||||
},
|
||||
function verify(issuer, profile, cb) {
|
||||
console.log('Get a google login:', profile)
|
||||
return cb(null, profile)
|
||||
}
|
||||
)
|
||||
@@ -1,9 +1,11 @@
|
||||
import passport from 'passport'
|
||||
import PasswordStrategy from './passwordStrategy.js'
|
||||
import JwtStrategy from './jwtStrategy.js'
|
||||
import passwordStrategy from './passwordStrategy.js'
|
||||
import jwtStrategy from './jwtStrategy.js'
|
||||
import googleStrategy from './googleStrategy.js'
|
||||
|
||||
passport.use(PasswordStrategy)
|
||||
passport.use(JwtStrategy)
|
||||
passport.use(passwordStrategy)
|
||||
passport.use(jwtStrategy)
|
||||
passport.use(googleStrategy)
|
||||
|
||||
passport.serializeUser((user, done) => {
|
||||
process.nextTick(() => {
|
||||
|
||||
@@ -10,4 +10,8 @@ export default {
|
||||
hostPwd: get('HOST_PWD', ''),
|
||||
containerExpiry: get('EXPIRY', 1000 * 60 * 60),
|
||||
sessionMaxAge: get('SESSION_MAX_AGE', 1000 * 60 * 60 * 24 * 7),
|
||||
google: {
|
||||
clientID: get('GOOGLE_CLIENT_ID', ''),
|
||||
clientSecret: get('GOOGLE_CLIENT_SECRET', ''),
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user