@@ -486,6 +486,7 @@ export const auth = betterAuth({
486486 'google-forms' ,
487487 'google-vault' ,
488488 'google-groups' ,
489+ 'google-chat' ,
489490 'vertex-ai' ,
490491 'github-repo' ,
491492 'microsoft-dataverse' ,
@@ -1150,6 +1151,47 @@ export const auth = betterAuth({
11501151 } ,
11511152 } ,
11521153
1154+ {
1155+ providerId : 'google-chat' ,
1156+ clientId : env . GOOGLE_CLIENT_ID as string ,
1157+ clientSecret : env . GOOGLE_CLIENT_SECRET as string ,
1158+ discoveryUrl : 'https://accounts.google.com/.well-known/openid-configuration' ,
1159+ accessType : 'offline' ,
1160+ scopes : [
1161+ 'https://www.googleapis.com/auth/userinfo.email' ,
1162+ 'https://www.googleapis.com/auth/userinfo.profile' ,
1163+ 'https://www.googleapis.com/auth/chat.spaces.readonly' ,
1164+ 'https://www.googleapis.com/auth/chat.messages.create' ,
1165+ ] ,
1166+ prompt : 'consent' ,
1167+ redirectURI : `${ getBaseUrl ( ) } /api/auth/oauth2/callback/google-chat` ,
1168+ getUserInfo : async ( tokens ) => {
1169+ try {
1170+ const response = await fetch ( 'https://openidconnect.googleapis.com/v1/userinfo' , {
1171+ headers : { Authorization : `Bearer ${ tokens . accessToken } ` } ,
1172+ } )
1173+ if ( ! response . ok ) {
1174+ logger . error ( 'Failed to fetch Google user info' , { status : response . status } )
1175+ throw new Error ( `Failed to fetch Google user info: ${ response . statusText } ` )
1176+ }
1177+ const profile = await response . json ( )
1178+ const now = new Date ( )
1179+ return {
1180+ id : `${ profile . sub } -${ crypto . randomUUID ( ) } ` ,
1181+ name : profile . name || 'Google User' ,
1182+ email : profile . email ,
1183+ image : profile . picture || undefined ,
1184+ emailVerified : profile . email_verified || false ,
1185+ createdAt : now ,
1186+ updatedAt : now ,
1187+ }
1188+ } catch ( error ) {
1189+ logger . error ( 'Error in Google getUserInfo' , { error } )
1190+ throw error
1191+ }
1192+ } ,
1193+ } ,
1194+
11531195 {
11541196 providerId : 'vertex-ai' ,
11551197 clientId : env . GOOGLE_CLIENT_ID as string ,
0 commit comments