# OAuth IMAP

## Sources

| Download                                            | Sources                                    |
| --------------------------------------------------- | ------------------------------------------ |
| <https://github.com/pluginsGLPI/oauthimap/releases> | <https://github.com/pluginsGLPI/oauthimap> |

{% hint style="info" %}
Microsoft is gradually removing the TLS 1.0 and 1.1 protocols for all Microsoft 365 applications. In order to keep your collector running, you need to add the **Oauth IMAP** plugin, which is available in the marketplace.
{% endhint %}

{% hint style="info" %}
The Oauth tokens for the collector, retrieved during authentication with Azure by the OauthIMAP plugin, are "offline" tokens that delegate authorisation to a third-party application (GLPI). These tokens provide a renewal code that will be used by the application to renew them automatically without user intervention. You will therefore not be asked to re-authenticate after the 1st authorisation request.
{% endhint %}

***

## Requirements (self-hosted)

| GLPI Version | Minimum PHP | Recommended |
| ------------ | ----------- | ----------- |
| 10.0.x       | 8.1         | 8.2         |
| 11.0.x       | 8.2         | 8.4         |

{% hint style="info" %}
This plugin is available without a [GLPI Network](https://services.glpi-network.com/#offers) subscription. It is also available on [GLPI Cloud](https://glpi-network.cloud).
{% endhint %}

***

## Supported mail services

OAuth IMAP support :

* Gmail : <https://developers.google.com/gmail/imap/xoauth2-protocol?hl=fr>
* Entra : <https://learn.microsoft.com/fr-fr/power-platform/admin/connect-gmail-oauth2>

***

## Install the plugin

* Go to the marketplace. Download **Oauth IMAP** and enable it

<div align="left"><figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2FV8lnvGMjwO077a4b2nTN%2FOAuth-IMAP.png?alt=media&#x26;token=6b7c5f6d-0cbe-49bd-a057-ba35a21f8d62" alt="images/oauth-imap-1.png"><figcaption></figcaption></figure></div>

* Open the [Azure Portal](https://portal.azure.com/#home) for your tenant
* In the search box type **registration**
* then select **App registrations**

<div align="left"><figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2Fgit-blob-a55ae28b889aa63712c8656bfd20d809753e6d13%2Foauth-imap-2.png?alt=media" alt="images/oauth-imap-2.png"><figcaption></figcaption></figure></div>

Here are the configuration steps including configuration phases on the Entra side.

***

## Receiver with Entra

### Register your Entra application

#### Create the application

* Click on **New registration**
* Enter the desired name, select the type of account supported then enter the redirection URL (present in the configuration of the plugin from your GLPI interface: [https://XXXXXXXXXXXXXX/marketplace/oauthimap/front/authorization.callback.php](https://xxxxxxxxxxxxxx/marketplace/oauthimap/front/authorization.callback.php)) specifying the **Web** option
* Then click on **Register**.

<figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2Fgit-blob-a3abe0320642094b92b7fcb0e8a184bf966f9e81%2Foauth-imap-3.png?alt=media" alt="images/oauth-imap-3.png"><figcaption></figcaption></figure>

#### Add a secret

* In the **Certificates and secrets** tab
* Click on **Client secrets**
* Then **New client secret**

<figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2Fgit-blob-250443f57fcb775ee21561f41ebc4de995896d21%2Foauth-imap-4.png?alt=media" alt="images/oauth-imap-4.png"><figcaption></figcaption></figure>

* Enter a description and then an expiration date
* A secret **value** is then generated. Keep this value well because once you have left this page, it will no longer be recoverable

<div align="left"><figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2Fgit-blob-cbee62afbbe8d2f4bb21b5e48e3dfff22566787c%2Foauth-imap-5.png?alt=media" alt="images/oauth-imap-5.png"><figcaption></figcaption></figure></div>

* Return to the **Overview** tab and **copy** the following values ​​and the secret seen above

<div align="left"><figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2Fgit-blob-3f0a98a73fa08a03aa8ca4ac24358cbd97073a68%2Foauth-imap-6.png?alt=media" alt="images/oauth-imap-6.png"><figcaption></figcaption></figure></div>

#### Add API permissions

* In the **API Permissions** tab
* Click on **your API** (Microsoft Graph in this case)
* Then select **Delegated permission**
* Select :
  * email
  * offline\_access
  * openid
  * profile
  * IMAP.AccessAsUser.All

<figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2Fgit-blob-947e5453686abe89034587d1d2e4ab3b49e8137e%2Foauth-imap-11.png?alt=media" alt="images/oauth-imap-11.png"><figcaption></figcaption></figure>

***

### Setup GLPI

* Now go back to your GLPI interface **Setup > Application Aouth IMAP** and indicate the information collected previously :

<figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2Fgit-blob-d79743a63afcd5748746d1d884e75b6ff543e87d%2Foauth-imap-7.png?alt=media" alt="images/oauth-imap-7.png"><figcaption></figcaption></figure>

* Click **Add**
* Now in the **Oauth authorization** tab, click **Create an authorization**

<div align="left"><figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2Fgit-blob-2ae4bcef9bc4b9fcc393eb8336da480ee70f87b1%2Foauth-imap-8.png?alt=media" alt="images/oauth-imap-8.png"><figcaption></figcaption></figure></div>

* When you click on **Create authorization**, you will be redirected to the Microsoft services sign-in page
* Enter the email address and password of the account that will be used for the collector
* You will also need to accept the necessary permissions related to the plugin.

<div align="left"><figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2Fgit-blob-91e0cb67f28b8d3b62242847f4e9aacfc37649f2%2Foauth-imap-9.png?alt=media" alt="images/oauth-imap-9.png"><figcaption></figcaption></figure></div>

<figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2Fgit-blob-67879d45e7f6b14bf5d6074b0595d675d0a8381b%2Foauth-imap-10.png?alt=media" alt="images/oauth-imap-10.png"><figcaption></figcaption></figure>

***

## Receiver with Google

### Creating a project

* From your [Google console](https://console.cloud.google.com/) (administrator access is required), go to your organisation then new project

![New project creation](https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2FKULVoK903IK1UM1Hp4EX%2Foauth-imap-google-1.png?alt=media\&token=40b33f7e-2f96-4841-9f5d-17dca7d9481a)

* Enter the name of your project
* Click on **`Create`**

<div align="left"><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2FWPjhJDaVxibb46f9OpjA%2Foauth-imap-google-2.png?alt=media&#x26;token=c2d08338-5e45-492d-8f89-a86d2572ae92" alt="Validation of new project"></div>

* Return to your organisation,
* Select your project

![Select the new project](https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2F6w5Bk0WbE4z0WB4s7cWI%2Foauth-imap-google-3.png?alt=media\&token=e41fcd2d-0eb3-4570-9ca7-44260979fec3)

***

### Setting up Oauth access

* From the menu, click on **`APIs & Services`**.
* Then **`OAuth consent screen`**

<div align="left"><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2F7ZqNkTgBNBYnviFniNuE%2Foauth-imap-google-4.png?alt=media&#x26;token=2bdfa500-197c-4396-a511-c186a6a5b285" alt="Oauth consent screen"></div>

#### Application Information

* From the preview, click **`Get started`**
* Enter the application name and the user support email (users will be able to contact you with questions regarding their consent)

<figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2F7pKlSOGldPfrqDLHUjXy%2Foauth-imap-app-information.png?alt=media&#x26;token=7608916e-24b7-4cc2-8a08-7635c5aa9dc5" alt=""><figcaption><p>Application information</p></figcaption></figure>

#### Audience

* Indicate what type of audience will be able to use this application (here internal because the user who will be using the imap services is a user of the organization)

<figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2FGZdFKIDWcNBGr2eihHhS%2Foauth-imap-audience.png?alt=media&#x26;token=9dcee09b-6213-43bb-8548-54788a7abb86" alt=""><figcaption><p>Audience settings</p></figcaption></figure>

#### Contact information

* Enter the contact name (this contact is notified of changes made to the application)

<figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2FsE8MzU4aZ4WwKjDLAOP2%2Foauth-imap-contact.png?alt=media&#x26;token=bf323344-1b12-4b46-b28a-3758a9adbd57" alt=""><figcaption><p>Contact information</p></figcaption></figure>

***

### Google API Services User Data Policy

* Accept the Google API Services User Data Policy and click **`Continue`** and **`Create`**

<figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2FNYga5W5idwMKZ5cmacnb%2Foauth-imap-data-policy.png?alt=media&#x26;token=435abce4-1bdc-4b37-9ee4-d0722fc99e2b" alt=""><figcaption><p>Application finalization</p></figcaption></figure>

***

### Creating a Client

#### &#xD;Application Type

\
You now need to create an application client that will connect Google to your GLPI instance using an application ID and a client secret.

* In the **Clients** tab, click **`Create a client`**.
* Select **Web Application** as the application type.
* Enter a name for your application.

<figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2F9vjel1tNhgj67eRmwZzz%2Foauth-imap-web-app.png?alt=media&#x26;token=73e2b92b-9541-4075-8ddc-2caaa04517de" alt=""><figcaption><p>Added the web application</p></figcaption></figure>

#### Authorised redirect URIs

\
The return URL must be specified in this section. This URL is found in GLPI under **`Setup`** > **`OAuth IMAP`** > **`+ Add`**

<figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2FM5fRnWTAbQ0LAGrxEPy0%2Foauth-imap-url-callback.png?alt=media&#x26;token=32f56262-ae91-403b-9a45-8881c16b4a12" alt=""><figcaption><p>Retrieving the callback URL</p></figcaption></figure>

* Enter this URL in the **Authorised redirect URIs** section of your application.

<div align="left"><figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2FitygT2um7vAnJLMPDJJM%2Foauth-imap-uris-authorisees.png?alt=media&#x26;token=0fcc5f85-6611-4d93-a943-c23446c4f813" alt=""><figcaption><p>Inserting the return URL</p></figcaption></figure></div>

* Click **`Create`** to validate your application

***

### Application information

{% hint style="warning" %}
In the next step, the **client secret** will be displayed. Once you leave this screen, it will no longer be available. Remember to save it in a safe place.
{% endhint %}

The application is now created. The screen displays the application ID and the client secret, which you will need to enter in GLPI.

<div align="left"><figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2FaalDtYXTMLhrR9deM3D8%2Foauth-imap-secret-client.png?alt=media&#x26;token=ae3ecfa1-df92-4df4-9272-a1d1773e72ea" alt=""><figcaption></figcaption></figure></div>

<figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2FH6509D5qRLf3cbMgpfae%2Foauth-imap-info-glpi.png?alt=media&#x26;token=ce44546a-fe9b-4c03-aaee-42c1bd641896" alt=""><figcaption><p>Information entered in GLPI</p></figcaption></figure>

***

### Finalizing GLPI configuration

Once your application information is listed in GLPI, and your application is active, you can click on **`+ Add`**

<figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2FOUFUvbY2Cse9TcFjN5pE%2Foauth-imap-created.png?alt=media&#x26;token=50b2bcd4-7573-4e18-ac66-12fd84b3fd49" alt=""><figcaption><p>OAuth IMAP application created</p></figcaption></figure>

#### OAuth Authorization

OAuth authorization is required for GLPI to use the IMAP services for the mailbox in question.

* From the **OAuth Authorization** tab, click **`+ Create authorization`**.
* Specify the account authorized to use the IMAP services.

<figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2FVsK83uGeV6juO0FaxIig%2Foauth-imap-authorization-oauth.png?alt=media&#x26;token=f53c2ff7-c1d4-43cd-993a-aaddb937ba13" alt=""><figcaption><p>OAuth Authorization</p></figcaption></figure>

***

### Receiver configuration

* From **`Configuration`** > **`Receivers`** > **`+ Add`**
* Specify the server **`imap.google.com`**
* In **Connection options**, select the previously created **IMAP OAuth** application
* In Username, select the user with OAuth permissions

<figure><img src="https://3573604317-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUCcURk2xlvtpVGbiRZf%2Fuploads%2Fs1a236ULWkyDOrKY5DOH%2Foauth-imap-setup-receiver.png?alt=media&#x26;token=020940cc-943e-41f3-a781-4acf47042df1" alt=""><figcaption><p>Receiver configuration</p></figcaption></figure>

***

## FAQ

If you have any questions about using the plugin, please consult our FAQ

<a href="https://app.gitbook.com/s/SvoJ3lioglS2UZLcWWyP/plugins/oauth-imap" class="button secondary">Go to FAQ</a>
