mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-02-06 12:13:07 +00:00
auth/google: Fix weird type error 🏷️ 🐛
Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
6e8ea859cd
commit
287148f1e8
1 changed files with 17 additions and 4 deletions
|
@ -1,20 +1,33 @@
|
||||||
import { Router } from 'express'
|
import { Router } from 'express'
|
||||||
import { AuthMiddleware } from '../interface'
|
|
||||||
import passport from 'passport'
|
import passport from 'passport'
|
||||||
import * as Google from 'passport-google-oauth20'
|
import * as Google from 'passport-google-oauth20'
|
||||||
import {config} from '../../../config'
|
import { config } from '../../../config'
|
||||||
|
import { AuthMiddleware } from '../interface'
|
||||||
import { passportGeneralCallback } from '../utils'
|
import { passportGeneralCallback } from '../utils'
|
||||||
|
|
||||||
const googleAuth = Router()
|
const googleAuth = Router()
|
||||||
|
|
||||||
export const GoogleMiddleware: AuthMiddleware = {
|
export const GoogleMiddleware: AuthMiddleware = {
|
||||||
getMiddleware (): Router {
|
getMiddleware: function (): Router {
|
||||||
passport.use(new Google.Strategy({
|
passport.use(new Google.Strategy({
|
||||||
clientID: config.google.clientID,
|
clientID: config.google.clientID,
|
||||||
clientSecret: config.google.clientSecret,
|
clientSecret: config.google.clientSecret,
|
||||||
callbackURL: config.serverURL + '/auth/google/callback',
|
callbackURL: config.serverURL + '/auth/google/callback',
|
||||||
userProfileURL: 'https://www.googleapis.com/oauth2/v3/userinfo'
|
userProfileURL: 'https://www.googleapis.com/oauth2/v3/userinfo'
|
||||||
}, passportGeneralCallback))
|
}, (
|
||||||
|
accessToken: string,
|
||||||
|
refreshToken: string,
|
||||||
|
profile: any,
|
||||||
|
done) => {
|
||||||
|
/*
|
||||||
|
This ugly hack is neccessary, because the Google Strategy wants a done-callback with an err as Error | null | undefined
|
||||||
|
but the passportGeneralCallback (and every other PassportStrategy) want a done-callback with err as string | Error | undefined
|
||||||
|
Note the absence of null. The lambda converts all `null` to `undefined`.
|
||||||
|
*/
|
||||||
|
passportGeneralCallback(accessToken, refreshToken, profile, (err?, user?) => {
|
||||||
|
done(err === null ? undefined : err, user)
|
||||||
|
})
|
||||||
|
}))
|
||||||
|
|
||||||
googleAuth.get('/auth/google', function (req, res, next) {
|
googleAuth.get('/auth/google', function (req, res, next) {
|
||||||
const authOpts = { scope: ['profile'], hostedDomain: config.google.hostedDomain }
|
const authOpts = { scope: ['profile'], hostedDomain: config.google.hostedDomain }
|
||||||
|
|
Loading…
Reference in a new issue