> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xynehq.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Service Account

> Setting up login via Google Service Account

This guide assumes you've already configured your google credentials, incase you haven't follow the guide below to first do that :

<Card title="Setup Google Credentials" icon="google" href="/authentication/get-credentials">
  Setup your Google Credentials for the application.
</Card>

### Setting up the Service Account and Credentials

First, from the menubar on the side, navigate to the `IAM & Admin` section. In there look for the `Service Account` section. Or directly visit [here](https://console.cloud.google.com/iam-admin/serviceaccounts), and then select your project.
In there click on  `+ CREATE SERVICE ACCOUNT `.

<img height="200" src="https://mintcdn.com/xyne/fT_nFAUVpQYF8W2t/images/crt-srv-acc.png?fit=max&auto=format&n=fT_nFAUVpQYF8W2t&q=85&s=b958f3c154e556228cb54a2de958e103" data-path="images/crt-srv-acc.png" />

Here, you will see the form that requires you to fill all the details about your service account.

<img height="200" src="https://mintcdn.com/xyne/fT_nFAUVpQYF8W2t/images/serv-acc1.png?fit=max&auto=format&n=fT_nFAUVpQYF8W2t&q=85&s=2309d47b21acdc89bd8b560d7c9f6b5a" data-path="images/serv-acc1.png" />

Once you've filled out the details, click on `CREATE AND CONTINUE`

* Grant the roles, based on the internal policies preferred by your organization, in the account.

<img height="200" src="https://mintcdn.com/xyne/fT_nFAUVpQYF8W2t/images/sacc-role.png?fit=max&auto=format&n=fT_nFAUVpQYF8W2t&q=85&s=3c3d37dd6d9142d567202464db9f42d5" data-path="images/sacc-role.png" />

* Click on `continue`.

* Optionally you can allow a list of users to access the service account:

<img height="200" src="https://mintcdn.com/xyne/fT_nFAUVpQYF8W2t/images/serv-acc3.png?fit=max&auto=format&n=fT_nFAUVpQYF8W2t&q=85&s=fdd7590bd79d33f030af844b70650eff" data-path="images/serv-acc3.png" />

* Click on `Done`

* Once the service account has been created, you'll be navigated to the service account details page where you can now configure your key..

* In the `Service Account` section where you can see your newly created service account, you will find a `KEYS` tab.

<img height="200" src="https://mintcdn.com/xyne/fT_nFAUVpQYF8W2t/images/sacdet.png?fit=max&auto=format&n=fT_nFAUVpQYF8W2t&q=85&s=2c457d0b7430434b32b7df87d0505954" data-path="images/sacdet.png" />

* In there navigate to the `keys` tab.
* Click on `ADD KEY`, followed by clicking on `Create New Key`

<img height="200" src="https://mintcdn.com/xyne/fT_nFAUVpQYF8W2t/images/serv-acc4.png?fit=max&auto=format&n=fT_nFAUVpQYF8W2t&q=85&s=cabea6d4e8fe4720ddeb85cdeaba5e22" data-path="images/serv-acc4.png" />

* Choose the `json` option for downloading the key file, and click on `Create`.

<img height="200" src="https://mintcdn.com/xyne/fT_nFAUVpQYF8W2t/images/serv-acc5.png?fit=max&auto=format&n=fT_nFAUVpQYF8W2t&q=85&s=20eb0e39a42ed08435b60a922e35e715" data-path="images/serv-acc5.png" />

* Remember the `Client id` associated with this json file.
* Once the key file has been created, choose a reliable location for downloading the key file, this will be used for putting it in the [`.env` of the application](https://docs.xynehq.com/quickstart#setting-the-environment-variables)

## Enabling APIs

Switch to the new project you just created.

The first step is to enable the APIs which are needed for the app.

* From the menu in the Sidebar, under APIs and Services section select the `Enabled APIs & Services`.

<img height="200" src="https://mintcdn.com/xyne/fT_nFAUVpQYF8W2t/images/enable-apis1.png?fit=max&auto=format&n=fT_nFAUVpQYF8W2t&q=85&s=9fd41aaae092f089dd4badc8e8ac2a76" data-path="images/enable-apis1.png" />

* In the `Enabled APIs & Services` page, click on the `+ Enable APIs & Services`.

<img height="200" src="https://mintcdn.com/xyne/fT_nFAUVpQYF8W2t/images/enable-apis2.png?fit=max&auto=format&n=fT_nFAUVpQYF8W2t&q=85&s=ce7c3ff0cf8ed371fd5d5e579259c6dc" data-path="images/enable-apis2.png" />

* You will now see a search box where you can search for the specific API that you want to enable. (For example :  Google Drive API)

<img height="200" src="https://mintcdn.com/xyne/fT_nFAUVpQYF8W2t/images/enable-apis3.png?fit=max&auto=format&n=fT_nFAUVpQYF8W2t&q=85&s=611e1caed2401f312d9e82bb598d6070" data-path="images/enable-apis3.png" />

* Once you search for an API, you will find a list of APIs.

<img height="200" src="https://mintcdn.com/xyne/fT_nFAUVpQYF8W2t/images/enable-apis4.png?fit=max&auto=format&n=fT_nFAUVpQYF8W2t&q=85&s=643d457161522a8f5d1b9bf4d8deb570" data-path="images/enable-apis4.png" />

* From the list of APIs, select the Google Drive API to enable. And then click on `Enable` in the API page.

<img height="200" src="https://mintcdn.com/xyne/fT_nFAUVpQYF8W2t/images/enable-apis5.png?fit=max&auto=format&n=fT_nFAUVpQYF8W2t&q=85&s=c67655cc53a00a63b211ebdc63f3cd7e" data-path="images/enable-apis5.png" />

* Once the API is enabled, you will see that the Enable button now changes to `Manage`. This means that the API has been enabled.

<img height="200" src="https://mintcdn.com/xyne/fT_nFAUVpQYF8W2t/images/enable-apis6.png?fit=max&auto=format&n=fT_nFAUVpQYF8W2t&q=85&s=ed8332edfaeaab3549d3a14952dfd6f1" data-path="images/enable-apis6.png" />

* When you go back to the `Enabled APIs & Services` page, you will see that the enabled API has appeared in the list.

<img height="200" src="https://mintcdn.com/xyne/fT_nFAUVpQYF8W2t/images/enable-apis7.png?fit=max&auto=format&n=fT_nFAUVpQYF8W2t&q=85&s=01bf9ce40a9aabb23f727addcec4064b" data-path="images/enable-apis7.png" />

Following the same steps above, enable the following APIs :

* [Google Drive](https://console.cloud.google.com/apis/library/drive.googleapis.com)
* [Google Calendar](https://console.cloud.google.com/apis/library/calendar-json.googleapis.com)
* [Google Slides](https://console.cloud.google.com/apis/library/slides.googleapis.com)
* [Google Docs](https://console.cloud.google.com/apis/library/docs.googleapis.com)
* [Google Sheets](https://console.cloud.google.com/apis/library/sheets.googleapis.com)
* [Gmail](https://console.cloud.google.com/apis/library/gmail.googleapis.com)
* [Contacts](https://console.cloud.google.com/apis/library/contacts.googleapis.com)
* [People](https://console.cloud.google.com/apis/library/people.googleapis.com)
* [Admin SDK](https://console.cloud.google.com/marketplace/product/google/admin.googleapis.com)

<Warning> Please make sure to **enable all** the APIs listed above to ensure the Xyne app runs smoothly. </Warning>

## Setting up Delegation

* Now that all of this is done, the `Workspace Admin` needs to do some delegations, navigate to [Domain Wide Delegation](https://admin.google.com/ac/owl/domainwidedelegation).
* Click on `Add New`

<img height="200" src="https://mintcdn.com/xyne/fT_nFAUVpQYF8W2t/images/add-new.png?fit=max&auto=format&n=fT_nFAUVpQYF8W2t&q=85&s=05c324025270854d21e22a063675e0f2" data-path="images/add-new.png" />

* In there paste the `OAuth Client Id` that you received when creating the service account key.
* Paste the following scopes :

```javascript theme={null}
https://www.googleapis.com/auth/drive.readonly,https://www.googleapis.com/auth/documents.readonly,https://www.googleapis.com/auth/spreadsheets.readonly,https://www.googleapis.com/auth/presentations.readonly,https://www.googleapis.com/auth/contacts.readonly,https://www.googleapis.com/auth/contacts.other.readonly,https://www.googleapis.com/auth/gmail.readonly,https://www.googleapis.com/auth/calendar.events.readonly,https://www.googleapis.com/auth/admin.directory.user.readonly
```

* Click on `Authorize`.
