[GH-ISSUE #421] Feature Request: Sign-in with Identity Token #8265

Closed
opened 2026-04-13 03:20:51 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @oktaysenkan on GitHub (Nov 5, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/421

Is your feature request related to a problem? Please describe.
I need to implement authentication with an OIDC ID token, but the current library doesn’t provide a direct method for this.

Describe the solution you'd like
I would like a method similar to supabase.auth.signInWithIdToken that allows signing in with an OIDC ID token.

Additional context
This example works with native login prompt.

import * as AppleAuthentication from 'expo-apple-authentication';

const credential = await AppleAuthentication.signInAsync({
    requestedScopes: [
        AppleAuthentication.AppleAuthenticationScope.FULL_NAME,
        AppleAuthentication.AppleAuthenticationScope.EMAIL,
    ],
});

console.log(credential.identityToken)

image

Supabase Reference

Originally created by @oktaysenkan on GitHub (Nov 5, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/421 **Is your feature request related to a problem? Please describe.** I need to implement authentication with an OIDC ID token, but the current library doesn’t provide a direct method for this. **Describe the solution you'd like** I would like a method similar to `supabase.auth.signInWithIdToken` that allows signing in with an OIDC ID token. **Additional context** This example works with native login prompt. ```tsx import * as AppleAuthentication from 'expo-apple-authentication'; const credential = await AppleAuthentication.signInAsync({ requestedScopes: [ AppleAuthentication.AppleAuthenticationScope.FULL_NAME, AppleAuthentication.AppleAuthenticationScope.EMAIL, ], }); console.log(credential.identityToken) ``` ![image](https://github.com/user-attachments/assets/e8626b85-cd04-4e03-a80a-4c04db7d0e9a) [Supabase Reference](https://supabase.com/docs/reference/javascript/auth-signinwithidtoken)
GiteaMirror added the locked label 2026-04-13 03:20:51 -05:00
Author
Owner

@abegehr commented on GitHub (Nov 10, 2024):

This is great! Using the Apple identityToken, do we still have to set clientId and clientSecret on the apple provider? If so, when generating the apple clientSecret it needs to have an expiration date. Is it fine to use a super-long-lived token for clientSecret? https://developer.apple.com/documentation/accountorganizationaldatasharing/creating-a-client-secret

<!-- gh-comment-id:2466757246 --> @abegehr commented on GitHub (Nov 10, 2024): This is great! Using the Apple identityToken, do we still have to set clientId and clientSecret on the apple provider? If so, when generating the apple clientSecret it needs to have an expiration date. Is it fine to use a super-long-lived token for clientSecret? https://developer.apple.com/documentation/accountorganizationaldatasharing/creating-a-client-secret
Author
Owner

@abegehr commented on GitHub (Nov 10, 2024):

Max. token lifetime that apple excepts seems to be 6 months: https://github.com/Faruqt/generate-apple-client-secret-key?tab=readme-ov-file#generate-apple-client-secret-key - therefore best-case would be to generate a clientSecret in the application itself from the p8-key.

<!-- gh-comment-id:2466761201 --> @abegehr commented on GitHub (Nov 10, 2024): Max. token lifetime that apple excepts seems to be 6 months: https://github.com/Faruqt/generate-apple-client-secret-key?tab=readme-ov-file#generate-apple-client-secret-key - therefore best-case would be to generate a clientSecret in the application itself from the p8-key.
Author
Owner

@abegehr commented on GitHub (Nov 10, 2024):

In case, we want to generate the apple client secret on-the-go in the future, here is a sample: https://github.com/WcaleNieWolny/capgo-social-login-backend-demo/blob/main/index.ts#L25

<!-- gh-comment-id:2466844842 --> @abegehr commented on GitHub (Nov 10, 2024): In case, we want to generate the apple client secret on-the-go in the future, here is a sample: https://github.com/WcaleNieWolny/capgo-social-login-backend-demo/blob/main/index.ts#L25
Author
Owner

@abegehr commented on GitHub (Nov 10, 2024):

I finally got "Sign-in with Apple" working on my iOS Capacitor app (should be the same for all hybrid platforms):

The main thing that tripped me up, is that better-auth requires clientId and clientSecret on socialProviders.apple in config -> this is where you're place the service id and jwt secret generated from p8-file for "Sign-in with Apple" on web.
However on native iOS, it doesn't use the service id but the app id (bundle id) as client id, so if using the service id as clientId in signIn.social() with idToken, it throws an error: JWTClaimValidationFailed: unexpected "aud" claim value.

For iOS native "SignIn with Apple" with idToken, it expects the app/bundle id as clientId and doesn't require the clientSecret.

<!-- gh-comment-id:2466911181 --> @abegehr commented on GitHub (Nov 10, 2024): I finally got "Sign-in with Apple" working on my iOS Capacitor app (should be the same for all hybrid platforms): The main thing that tripped me up, is that better-auth requires `clientId` and `clientSecret` on `socialProviders.apple` in config -> this is where you're place the service id and jwt secret generated from p8-file for "Sign-in with Apple" on web. However on native iOS, it doesn't use the service id but the app id (bundle id) as client id, so if using the service id as clientId in `signIn.social()` with `idToken`, it throws an error: `JWTClaimValidationFailed: unexpected "aud" claim value`. For iOS native "SignIn with Apple" with idToken, it expects the app/bundle id as `clientId` and doesn't require the `clientSecret`.
Author
Owner

@tlebeitsuk commented on GitHub (Dec 12, 2024):

I finally got "Sign-in with Apple" working on my iOS Capacitor app (should be the same for all hybrid platforms):

The main thing that tripped me up, is that better-auth requires clientId and clientSecret on socialProviders.apple in config -> this is where you're place the service id and jwt secret generated from p8-file for "Sign-in with Apple" on web. However on native iOS, it doesn't use the service id but the app id (bundle id) as client id, so if using the service id as clientId in signIn.social() with idToken, it throws an error: JWTClaimValidationFailed: unexpected "aud" claim value.

For iOS native "SignIn with Apple" with idToken, it expects the app/bundle id as clientId and doesn't require the clientSecret.

Thanks for the heads up! This should be added to the docs.

<!-- gh-comment-id:2538078924 --> @tlebeitsuk commented on GitHub (Dec 12, 2024): > I finally got "Sign-in with Apple" working on my iOS Capacitor app (should be the same for all hybrid platforms): > > The main thing that tripped me up, is that better-auth requires `clientId` and `clientSecret` on `socialProviders.apple` in config -> this is where you're place the service id and jwt secret generated from p8-file for "Sign-in with Apple" on web. However on native iOS, it doesn't use the service id but the app id (bundle id) as client id, so if using the service id as clientId in `signIn.social()` with `idToken`, it throws an error: `JWTClaimValidationFailed: unexpected "aud" claim value`. > > For iOS native "SignIn with Apple" with idToken, it expects the app/bundle id as `clientId` and doesn't require the `clientSecret`. Thanks for the heads up! This should be added to the docs.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8265