Implement ChatGPT plugins user authentication with Logto
Tags: chatgpt, webdev, tutorial, beginners
Published: 2023-05-24 19:18:07

## Introduction

- [Logto](https://logto.io/) is an effortless identity solution with all the features you need. It supports various sign-in methods, including username, email, phone number, and popular social sign-ins like Google and GitHub.
- [ChatGPT plugins](https://openai.com/blog/chatgpt-plugins) are tools designed specifically for language models, and help ChatGPT access up-to-date information, run computations, or use third-party services.

In this article, we will demonstrate how to use Logto as an OAuth identity provider for ChatGPT plugins. If you're curious about the importance of authentication for your plugins, check out this post: [Authentication: The differentiator for ChatGPT plugins](https://blog.logto.io/authentication-the-differentiator-for-chatgpt-plugins/?utm_source=dev&utm_medium=chatgpt_plugins_auth).

> We want to give a big shoutout to our community member, kAd, for their invaluable help in validating this integration. We are extremely grateful for their efforts, as this tutorial wouldn't have been possible without their assistance. Tc001 also provided meaningful input during the process.

## Prerequisites

To get started, make sure you have the following:

- A running Logto instance or access to a Logto Cloud account.
- A ChatGPT account with developer access for plugins. While ChatGPT plugins are available to all Plus members, you'll still need to join the waitlist to get developer access.

## Configure Logto

If you are self-hosting Logto, refer to the Logto "[Get started](https://docs.logto.io/docs/tutorials/get-started/)" documentation to set up your Logto instance.

Open Logto Console by entering the URL `https://cloud.logto.io/` if you are using Logto Cloud, or the endpoint you have set up for self-hosting.

---

<center>
<a href="http://cloud.logto.io?sign_up=true&utm_source=dev&utm_medium=chatgpt_plugins_auth" target="_blank">Open Logto Cloud and effortlessly complete the configuration</a>
</center>

---

Next, navigate to the "Applications" tab and click on "Create Application".

![Applications tab](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j7d5wf4b09hjgpgjjxx1.png)

In the modal that appears, choose "Traditional Web" and provide an application name, such as "My ChatGPT plugin." Click on "Create Application.”

![Create application](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7kf5rl93usfyec93bvuy.png)

You will be directed to a tutorial page in Logto. Click on "Skip" at the top-right corner to proceed to the Application details page.

![Applications details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zpnrsm9peddiwem5qlse.png)


In the "Redirect URIs" section, enter the following value:

```
https://chat.openai.com/aip/[your-plugin-id]/oauth/callback
```

For example, if your plugin ID is `foo123`, the value should be:

```
https://chat.openai.com/aip/foo123/oauth/callback
```

![Redirect URIs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/irueutrnjvdr69xtfsg5.png)

Scroll down to the "Advanced settings" section and enable "Always issue Refresh Token" (this helps ChatGPT maintain the authentication state).

![Always issue Refresh Token toggle](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v29aof9vtotg5opr8h44.png)

Click on the "Save Changes" button at the bottom. Keep this page open as it will be useful for configuring plugin later.

![Save changes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gsmthqck97rc33i2svqe.png)

## Configure ChatGPT plugin

Follow the steps outlined in the [ChatGPT Plugins documentation](https://platform.openai.com/docs/plugins/introduction) until you reach the authentication configuration step. Since ChatGPT plugin supports OAuth authentication providers, you can easily find most of the required configuration values on the Logto application details page.

When setting up your plugin with ChatGPT, you will need to provide your OAuth Client ID and Client Secret. These correspond to the “App ID” and “App Secret” on the Logto page.

![ChatGPT plugin OAuth credentials](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hnfsiwjdgv3w8l6bg6xf.png)

For the auth section in the `ai-plugin.json`, use the following template:

```json
"auth": {
  "type": "oauth",
  "client_url": "[Authorization Endpoint in Logto]",
  "scope": "openid profile email",
  "authorization_url": "[Token Endpoint in Logto]",
  "authorization_content_type": "application/json",
  "verification_tokens": {
    "openai": "Replace_this_string_with_the_verification_token_generated_in_the_ChatGPT_UI"
  }
}
```

Remember to replace the `client_url` and `authorization_url` values with the respective values from Logto. You can find and copy them from the "Advanced settings" section on the Logto application details page.

![Advanced settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2nknkkcxm1bj3y9nq9q.png)

## Checkpoint: Test Logto and ChatGPT plugin integration

The ChatGPT UI will automatically prompt you to install the plugin. Once successful, you will see a dialog with a button that says "Log in with [your plugin name]."

![ChatGPT plugin login](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tcoyk6gisuh9x7tygnua.png)

Click on the button, and you will be directed to the Logto sign-in experience.

![Logto sign-in experience](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o8y0k9wp7kv81dk5n6fb.png)

If everything is configured correctly, once you complete the sign-in or registration process in Logto, you will be redirected back to ChatGPT. From now on, every request sent by ChatGPT to your plugin server will carry the Authorization header, allowing you to decode and verify the token in your API.

And that wraps up our guide on implementing ChatGPT plugins user authentication with Logto. If you encounter any issues during the integration, please don't hesitate to contact us via email at contact@logto.io or [join our Discord server](https://discord.gg/UEPaF3j5e6)!

---

<center><a href="http://cloud.logto.io?sign_up=true&utm_source=dev&utm_medium=chatgpt_plugins_auth" target="_blank">Try Logto today</a></center>