feat: request additional scopes from user #501

Closed
opened 2026-03-13 07:50:05 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @sudipbuilds on GitHub (Dec 31, 2024).

Is this suited for github?

  • Yes, this is suited for github

Hey! I'm currently working on an app that requires users to grant access to their GitHub repositories to function properly. I know additional scopes can be added to better-auth's configuration during user sign-up. However, users might not want to grant repository access on their first visit.

import { betterAuth } from "better-auth";

export const auth = betterAuth({
  appName: "Auth Test",
  socialProviders: {
    github: {
      clientId: process.env.GITHUB_CLIENT_ID!,
      clientSecret: process.env.GITHUB_CLIENT_SECRET!,
      scope: ["repo"], // additional scopes apart from which are used by default for retrieving common user information
    },
  },
});

Describe the solution you'd like

I would like a flow where even if additional scopes are not written in the config, I should be able to request those post sign-up when needed. An example of this can be -

async function getGithubAccess() {
  await authClient.signIn.social(
    { provider: "github" },
    { scopes: ["repo"] }
  );
}

<button onClick={getGithubAccess}>Give access to your github repositories</button>

Also update the access token and refresh token in database.

Describe alternatives you've considered

Using Clerk, this can be achieved using the component by passing additionalOAuthScopes prop, but it doesn’t offer much control.

Source - https://clerk.com/docs/authentication/social-connections/oauth#request-additional-o-auth-scopes-after-sign-up

Additional context

No response

Originally created by @sudipbuilds on GitHub (Dec 31, 2024). ### Is this suited for github? - [ ] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Hey! I'm currently working on an app that requires users to grant access to their GitHub repositories to function properly. I know additional scopes can be added to better-auth's configuration during user sign-up. However, users might not want to grant repository access on their first visit. ```ts import { betterAuth } from "better-auth"; export const auth = betterAuth({ appName: "Auth Test", socialProviders: { github: { clientId: process.env.GITHUB_CLIENT_ID!, clientSecret: process.env.GITHUB_CLIENT_SECRET!, scope: ["repo"], // additional scopes apart from which are used by default for retrieving common user information }, }, }); ``` ### Describe the solution you'd like I would like a flow where even if additional scopes are not written in the config, I should be able to request those post sign-up when needed. An example of this can be - ```ts async function getGithubAccess() { await authClient.signIn.social( { provider: "github" }, { scopes: ["repo"] } ); } <button onClick={getGithubAccess}>Give access to your github repositories</button> ``` Also update the access token and refresh token in database. ### Describe alternatives you've considered Using Clerk, this can be achieved using the <UserButton /> component by passing `additionalOAuthScopes` prop, but it doesn’t offer much control. Source - https://clerk.com/docs/authentication/social-connections/oauth#request-additional-o-auth-scopes-after-sign-up ### Additional context _No response_
Author
Owner

@arthberman commented on GitHub (Dec 31, 2024):

+1

@arthberman commented on GitHub (Dec 31, 2024): +1
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#501