[GH-ISSUE #793] Google provider ignores the scopes I add #25758

Closed
opened 2026-04-17 16:02:00 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @saulogt on GitHub (Dec 6, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/793

Describe the bug
I add passing additional scope to the provider (like 'https://www.googleapis.com/auth/business.manage') but the consent screen is alway the same basic thing

By continuing, Google will share your name, email address, language preference, and profile picture with Company. See Company’s Privacy Policy and Terms of Service.
The scope store in the database is always "https://www.googleapis.com/auth/userinfo.profile,openid,https://www.googleapis.com/auth/userinfo.email"

Without the right scope, I can not use any additional apis on Google. I understand the main purpose of Better auth is not that, but the feature seems to be broken

To Reproduce
Steps to reproduce the behavior:

  1. Create the basic auth configuration with the extra scope:
import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { db } from '../db';

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: 'pg',
  }),
  socialProviders: {
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID!,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
      // redirectURI: `${process.env.NEXT_PUBLIC_APP_URL}/app`,
      prompt: 'consent',
      scopes: [
        'https://www.googleapis.com/auth/userinfo.profile',
        'https://www.googleapis.com/auth/userinfo.email',
        'openid',
        'https://www.googleapis.com/auth/business.manage',
      ],
    },
  },
});
  1. Login - Note the consent
  2. Check the database

Expected behavior
Google provider should respect the scopes provided

Screenshots

2024-12-06 14-27-29

Desktop (please complete the following information):

  • OS: MacOS
  • Browser Chrome
  • Version Canary 133.0.6880.1

Smartphone (please complete the following information):
N/A

Additional context
N/A

Originally created by @saulogt on GitHub (Dec 6, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/793 **Describe the bug** I add passing additional scope to the provider (like 'https://www.googleapis.com/auth/business.manage') but the consent screen is alway the same basic thing >By continuing, Google will share your name, email address, language preference, and profile picture with Company. See Company’s Privacy Policy and Terms of Service. The scope store in the database is always "https://www.googleapis.com/auth/userinfo.profile,openid,https://www.googleapis.com/auth/userinfo.email" Without the right scope, I can not use any additional apis on Google. I understand the main purpose of Better auth is not that, but the feature seems to be broken **To Reproduce** Steps to reproduce the behavior: 1. Create the basic auth configuration with the extra scope: ```ts import { betterAuth } from 'better-auth'; import { drizzleAdapter } from 'better-auth/adapters/drizzle'; import { db } from '../db'; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: 'pg', }), socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID!, clientSecret: process.env.GOOGLE_CLIENT_SECRET!, // redirectURI: `${process.env.NEXT_PUBLIC_APP_URL}/app`, prompt: 'consent', scopes: [ 'https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email', 'openid', 'https://www.googleapis.com/auth/business.manage', ], }, }, }); ``` 2. Login - Note the consent 3. Check the database **Expected behavior** Google provider should respect the scopes provided **Screenshots** ![2024-12-06 14-27-29](https://github.com/user-attachments/assets/6065f173-72a7-4e37-8795-b54b191c65eb) **Desktop (please complete the following information):** - OS: MacOS - Browser Chrome - Version Canary 133.0.6880.1 **Smartphone (please complete the following information):** N/A **Additional context** N/A
GiteaMirror added the locked label 2026-04-17 16:02:00 -05:00
Author
Owner

@Bekacru commented on GitHub (Dec 7, 2024):

As you can see, the scopes are appended rather than overridden. Since the default ones are necessary scopes for retrieving user info, the ones you add function more as additional scopes.

<!-- gh-comment-id:2524991499 --> @Bekacru commented on GitHub (Dec 7, 2024): As you can see, the scopes are appended rather than overridden. Since the default ones are necessary scopes for retrieving user info, the ones you add function more as additional scopes.
Author
Owner

@saulogt commented on GitHub (Dec 8, 2024):

Thanks for the answer @Bekacru
I understand that. So why I don't see the additional scope in the list? This is the missing scope: https://www.googleapis.com/auth/business.manage

<!-- gh-comment-id:2525566459 --> @saulogt commented on GitHub (Dec 8, 2024): Thanks for the answer @Bekacru I understand that. So why I don't see the additional scope in the list? This is the missing scope: https://www.googleapis.com/auth/business.manage
Author
Owner

@Bekacru commented on GitHub (Dec 8, 2024):

https://www.googleapis.com/auth/userinfo.email has been added. The scope stored in the db is the one returned by the provider (Google). The provider might not include every scope you requested—it may ignore certain scopes for various reasons. Check if the authorizationURL includes the requested scopes.

<!-- gh-comment-id:2525574753 --> @Bekacru commented on GitHub (Dec 8, 2024): `https://www.googleapis.com/auth/userinfo.email` has been added. The scope stored in the db is the one returned by the provider (Google). The provider might not include every scope you requested—it may ignore certain scopes for various reasons. Check if the `authorizationURL` includes the requested scopes.
Author
Owner

@cprecioso commented on GitHub (Dec 8, 2024):

Hi @Bekacru, I am facing the same problem as the OP (but with the https://www.googleapis.com/auth/gmail.modify scope).
The new scope is passed to the Google OAuth flow, I confirmed it on their screen, and then the scope is passed back to Better Auth.

image

However the scope is still not being updated in the database, which still has the default scopes.

If I manually delete the account on the DB and retry the login, the scopes are stored correctly (with all my manual ones), so it'd seem that for an existing account, the scope column is not being updated in the DB when re-logging-in.

<!-- gh-comment-id:2526182656 --> @cprecioso commented on GitHub (Dec 8, 2024): Hi @Bekacru, I am facing the same problem as the OP (but with the `https://www.googleapis.com/auth/gmail.modify` scope). The new scope is passed to the Google OAuth flow, I confirmed it on their screen, and then the scope is passed back to Better Auth. <img width="1525" alt="image" src="https://github.com/user-attachments/assets/974372a0-2e4d-4010-a2d5-3455bafaf402"> However the scope is still not being updated in the database, which still has the default scopes. If I manually delete the account on the DB and retry the login, the scopes are stored correctly (with all my manual ones), so it'd seem that for an existing account, the `scope` column is not being updated in the DB when re-logging-in.
Author
Owner

@Bekacru commented on GitHub (Jan 13, 2025):

fixed on 2161eb159d

<!-- gh-comment-id:2587174585 --> @Bekacru commented on GitHub (Jan 13, 2025): fixed on https://github.com/better-auth/better-auth/commit/2161eb159d45a116aeef63df076f9a2a3922fbc7
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#25758