# Google oAuth

### How get clientID and secret key

[How to install a plugin](/plugins/using-plugins/user-authentication-plugins-not-web3/google-oauth-plugin.md)

### Auth by native app

## Auth with Google oAuth

<mark style="color:green;">`POST`</mark> `https://api.directual.com/good/v4/auth`

#### Request Body

| Name          | Type   | Description                                                                              |
| ------------- | ------ | ---------------------------------------------------------------------------------------- |
| appID         | string | id of your app (go to API → API keys, create key (if there is none) and copy APP\_ID) ID |
| provider      | string | google                                                                                   |
| code          | string | auth code after successful authentication                                                |
| clientID      | string | clientID google oAuth                                                                    |
| redirect\_uri | string | redirect\_uri                                                                            |

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

```javascript
{
  "result":{
    "token": "8ba4aee8-f509-41d0-9c59-232e828a41a6",
    "username": "test",
    "role": ""
  },
  "status": "ok"
}
```

{% endtab %}

{% tab title="404 " %}

```javascript
{
  "msg":"user or password incorrect",
  "status":"error"
}
```

{% endtab %}
{% endtabs %}

```
curl -X PUT -H "Content-Type: application/json" \ https://api.directual.com/good/v4/auth \
-d '{
  "appID":"de87a6f7-a1e5-4b31-9d13-37c842b259a",
  "provider": "google"
  "code": "37c842b259a...",
  "clientID": "de87a6f7....",
  "redirect_uri": "http://mywebsite.app/login"
}'
```

### Example auth for React js

Install google-login plugin

```
npm install react-google-login --save
```

Insert login button to your LoginPage template, example:

```
import { GoogleLogin } from 'react-google-login';

<GoogleLogin
          clientId={you_client_id}
          buttonText="Login"
          accessType={"offline"}
          responseType={"code"}
          onSuccess={(d)=>{
              let url = `http://api.directual.com/good/api/v4/auth/`
              let body = { provider: "google", token: d.code, clientID: you_client_id  }
              fetch(url, {
                method: 'POST',
                body: JSON.stringify(req.body),
                headers: {
                  'Content-Type': 'application/json'
                }
              }).then(res2=>{
                res2.json().then(result=>{
                  res.end(JSON.stringify(result))
                }).catch((data)=>{
                  res.end('error')
                })
            
              })
          }}
          onFailure={(d)=>{

          }}
          cookiePolicy={'single_host_origin'}
      />
```


---

# 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://readme.directual.com/api-integrations/authentication-api/google-oauth.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.
