[GH-ISSUE #549] Google Signin from an API endpoint #25640

Closed
opened 2026-04-17 15:53:39 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @MrKepzie on GitHub (Nov 15, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/549

I have a custom POST endpoint that is called from a desktop application.
The endpoint should authentificate the user using the google provider.
The user has already at least once on the website registered with signInSocial, but from the endpoint context, the user is not signed-in (nothing in the cookies since it is not the web-browser).

What would be the way to programmaticallly signin the user on an endpoint ?
I tried the following:

const rep = await authClient.signIn.social(
            {
                provider: "google",
           }
);

But all I get is the URL from google to show the login request.
What I would like is a way to get the cookie so that I can call auth.api.getSession right away after signIn.social.
Is this workflow supported ?

Also as a side note, as I'm not familiar with google oauth workflow: Is the user always supposed to accept the request using the google-provided form when logging-in or just the first time ? For me it promps everytimes, but this may be because I'm using a test mode client on Google cloud ?

Originally created by @MrKepzie on GitHub (Nov 15, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/549 I have a custom POST endpoint that is called from a desktop application. The endpoint should authentificate the user using the google provider. The user has already at least once on the website registered with signInSocial, but from the endpoint context, the user is not signed-in (nothing in the cookies since it is not the web-browser). What would be the way to programmaticallly signin the user on an endpoint ? I tried the following: ``` const rep = await authClient.signIn.social( { provider: "google", } ); ``` But all I get is the URL from google to show the login request. What I would like is a way to get the cookie so that I can call `auth.api.getSession` right away after signIn.social. Is this workflow supported ? Also as a side note, as I'm not familiar with google oauth workflow: Is the user always supposed to accept the request using the google-provided form when logging-in or just the first time ? For me it promps everytimes, but this may be because I'm using a test mode client on Google cloud ?
GiteaMirror added the locked label 2026-04-17 15:53:39 -05:00
Author
Owner

@pakenfit commented on GitHub (Nov 26, 2024):

If you have the idToken from google you can use that to authenticate using :

await authClient.siginIn.social({
     provider: "google",
     idToken: {token: "your_id_token"}
})
<!-- gh-comment-id:2500294855 --> @pakenfit commented on GitHub (Nov 26, 2024): If you have the idToken from google you can use that to authenticate using : ```` await authClient.siginIn.social({ provider: "google", idToken: {token: "your_id_token"} }) ````
Author
Owner

@MrKepzie commented on GitHub (Nov 26, 2024):

Ok, but is there a way to get this token from better-auth?

<!-- gh-comment-id:2500670623 --> @MrKepzie commented on GitHub (Nov 26, 2024): Ok, but is there a way to get this token from better-auth?
Author
Owner

@pakenfit commented on GitHub (Nov 27, 2024):

I don't think better-auth itself provides methods to obtain Google's ID token directly, this needs to be obtained from Google's OAuth2 flow. For example in react-native app I use @react-native-google-signin/google-signin to get the idToken. For desktop app I don't know unfortunately.

<!-- gh-comment-id:2503457486 --> @pakenfit commented on GitHub (Nov 27, 2024): I don't think better-auth itself provides methods to obtain Google's ID token directly, this needs to be obtained from Google's OAuth2 flow. For example in `react-native` app I use `@react-native-google-signin/google-signin` to get the `idToken`. For desktop app I don't know unfortunately.
Author
Owner

@MrKepzie commented on GitHub (Nov 27, 2024):

That's what I figured. They have a C++ SDK I might take a look at when I have time

<!-- gh-comment-id:2504882210 --> @MrKepzie commented on GitHub (Nov 27, 2024): That's what I figured. They have a C++ SDK I might take a look at when I have time
Author
Owner

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

seems like resolved issue. feel free to re-open if not

<!-- gh-comment-id:2586241472 --> @Bekacru commented on GitHub (Jan 13, 2025): seems like resolved issue. feel free to re-open if not
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#25640