How to sign-in or link with providers via Admin SDK?

208 views
Skip to first unread message

Okan

unread,
May 29, 2023, 3:57:34 PM5/29/23
to Firebase Google Group
Currently, I am performing the sign-in and link flow on the client with Unity SDK. This has a number of disadvantages.

Since I can't edit the abandoned anonnymous account, the data of the abandoned accounts are not deleted.
There are custom conditions and logics that I want to operate at the time of the account switch.
Since we are a game, I always have to try the link first and then the sign in. This makes api cumbersome.
Since I can't use apple credentials twice, I have to ask user apple sign in twice if link attempt fails.

Maybe it's possible to solve all of this with things like cloud functions, new identity platform etc. But I don't want to deal with them when I can easily do it on my own server.

Okan

unread,
May 31, 2023, 11:46:14 PM5/31/23
to Firebase Google Group
For those who need same thing in the future.  I couldn't find anything in SDK but there is rest api. It is not difficult to implement.
https://firebase.google.com/docs/reference/rest/auth#section-link-with-oauth-credential

Example c# snippet
public async Task LinkWithOAuthCredential(string idToken, string providerToken, string providerId)
    {
        var result = await _httpClient.PostAsJsonAsync($"{BaseAddress}/accounts:signInWithIdp?key={_firebaseWebApiKey}", new
        {
            idToken,
            requestUri = "http://localhost",
            postBody = $"access_token={providerToken}&providerId={providerId}",
            returnSecureToken = true,
            returnIdpCredential = false,
        });
    }


29 Mayıs 2023 Pazartesi tarihinde saat 22:57:34 UTC+3 itibarıyla Okan şunları yazdı:

Okan

unread,
Jun 6, 2023, 12:26:16 PM6/6/23
to Firebase Google Group
Okay it is not difficult but also not easy at all because a lot of thing undocumented.
postBody parameter depends on provider.  For apple sign in    (provider id: apple.com) you need to send id_token (not access_token) and also need nonce.

$"id_token={ProviderToken}&providerId={ProviderId}&nonce={RawNonce}"

For google play games (provider id: playgames.google.com) you need auth code.  Sadly this is fully undocumented and nothing on internet. Luckily i got answer from chat gpt.
$"code={AuthCode}&providerId={ProviderId}";

1 Haziran 2023 Perşembe tarihinde saat 06:46:14 UTC+3 itibarıyla Okan şunları yazdı:
Reply all
Reply to author
Forward
0 new messages