# post\_\_auth\_google\_exchange

`POST /auth/google/exchange`

*Exchange Google Authorization Code*

Exchange Google authorization code for access token.

This endpoint completes the OAuth flow by exchanging an authorization code for an access token. Use this when you have an authorization code from the Google OAuth consent screen.

**OAuth Flow:**

1. Redirect user to Google OAuth consent screen
2. User authorizes your application
3. Google returns authorization code
4. Call this endpoint with the code
5. Receive access token for use with `/auth/google`

#### TypeScript Client Library

```typescript
private exchangeGoogleCode = async (code: string): Promise<OAuth2ResponseDTO> => {
  return this.makeRequest<OAuth2ResponseDTO>('auth/google/exchange', 'POST', { code });
};
```

#### Code Samples

{% tabs %}
{% tab title="Shell" %}

```shell
# You can also use wget
curl -X POST https://backend.flashback.tech/auth/google/exchange \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access-token}'
```

{% endtab %}

{% tab title="HTTP" %}

```http
POST https://backend.flashback.tech/auth/google/exchange HTTP/1.1
Host: localhost:3000
Content-Type: application/json
Accept: application/json
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const inputBody = '{
  "code": "4/0AfJohXn..."
}';
const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('https://backend.flashback.tech/auth/google/exchange',
{
  method: 'POST',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'rest-client'
require 'json'

headers = {
  'Content-Type' => 'application/json',
  'Accept' => 'application/json',
  'Authorization' => 'Bearer {access-token}'
}

result = RestClient.post 'https://backend.flashback.tech/auth/google/exchange',
  params: {
  }, headers: headers

p JSON.parse(result)
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'Authorization': 'Bearer {access-token}'
}

r = requests.post('https://backend.flashback.tech/auth/google/exchange', headers = headers)

print(r.json())
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

require 'vendor/autoload.php';

$headers = array(
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'Authorization' => 'Bearer {access-token}',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('POST','https://backend.flashback.tech/auth/google/exchange', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...
```

{% endtab %}

{% tab title="Java" %}

```java
URL obj = new URL("https://backend.flashback.tech/auth/google/exchange");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Content-Type": []string{"application/json"},
        "Accept": []string{"application/json"},
        "Authorization": []string{"Bearer {access-token}"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("POST", "https://backend.flashback.tech/auth/google/exchange", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}
```

{% endtab %}
{% endtabs %}

> Body parameter

```json
{
  "code": "4/0AfJohXn..."
}
```

**Parameters**

| Name   | In   | Type   | Required | Description                                         |
| ------ | ---- | ------ | -------- | --------------------------------------------------- |
| body   | body | object | true     | none                                                |
| » code | body | string | true     | Google authorization code from OAuth consent screen |

> Example responses

> 200 Response

```json
{
  "success": true,
  "token": "string",
  "refreshToken": "string",
  "expiresAt": 0
}
```

**Responses**

| Status | Meaning                                                 | Description               | Schema |
| ------ | ------------------------------------------------------- | ------------------------- | ------ |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | Token exchange successful | Inline |

**Response Schema**

Status Code **200**

| Name           | Type    | Required | Restrictions | Description                |
| -------------- | ------- | -------- | ------------ | -------------------------- |
| » success      | boolean | false    | none         | none                       |
| » token        | string  | false    | none         | Google access token        |
| » refreshToken | string  | false    | none         | Google refresh token       |
| » expiresAt    | integer | false    | none         | Token expiration timestamp |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flashback.tech/support-reference/platform-api-reference/authentication/post__auth_google_exchange.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
