Title: Flutter Google Sign In Couchbase Authentication Code Flow
Tags: authentication;oauth-2.0;google-oauth;openid-connect;couchbase-sync-gateway
Question: As we are migrating our app from Firebase to Couchbase, we also need to change the authentication part. We are using the google_sign_in package and would like to continue using it to have the native Google Sign In popup. Using the package we can get a serverAuthCode, which from my understanding we can then send to the _oidc_callback endpoint of Couchbase Sync Gateway. First I had to set disable_callback_state to true in the Sync Gateway configuration (&quot;DisableCallbackState determines whether or not to maintain state between the /_oidc and /_oidc_callback endpoints.&quot;). However, when I now send the serverAuthCode to the _oidc_callback endpoint, I get the following error with status code 500:
body: {&quot;error&quot;: &quot;Internal Server Error&quot;, &quot;reason&quot;: &quot;Failed to exchange token: oauth2: cannot fetch token: 400 Bad Request\nResponse: {\n \&quot;error\&quot;: \&quot;invalid_grant\&quot;,\n \&quot;error_description\&quot;: \&quot;Bad Request\&quot;\n}&quot;}
I assume it is because the login was done using the package and not through the browser with a redirect to the app afterwards. Now I have no idea how to do this correctly though, that I sign in with the google_sign_in package and then use the code to get the tokens from the Sync Gateway. I can't find any helpful information for this problem.
I would be very happy if someone could help me, possibly in a call. Maybe this way something like this can be solved faster.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2022:00:09/07/22', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<authentication><oauth-2.0><google-oauth><openid-connect><couchbase-sync-gateway>', 'Title': 'Flutter Google Sign In Couchbase Authentication Code Flow', 'ViewCount': 35, 'id': 73640905, 'user_AboutMe': "<p>Hello, my name is Florian. I am a web and Flutter developer from Germany.</p>\n<p>I started teaching myself programming at a young age. I began with the programming language Java for the development of Minecraft plugins. Later on I developed websites with PHP (besides HTML and CSS) and over time I also learned JavaScript basics. Further on, I also programmed with Python, before I learned Flutter and Dart by learning-by-doing during the development of an app.</p>\n<p>Currently, I'm actively working on an app using Flutter.</p>\n", 'user_AccountId': 19023078.0, 'user_DisplayName': 'PlutoHDDev', 'user_Reputation': 351.0, 'user_Views': 56.0, 'user_id': 13886744.0}}