> For the complete documentation index, see [llms.txt](https://docs.midio.com/midio-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.midio.com/midio-docs/guides/secrets-and-environment-variables/oauth-2.0-providers.md).

# OAuth 2.0

OAuth provides a standardized and secure way for applications (i.e. Google Sheets, Twitter etc.) to give access to resources on behalf of a user *without* the user having to share their credentials with Midio.

In Midio you can store client credentials and generate access tokens that are stored as `Secrets`. If the access tokens have an expiry time, Midio will automatically try to update them.

To enable this, you have to:

* Register and retrieve client credentials for the OAuth provider from an application. This is done outside of Midio. For instance, you can follow [this guide to set up a OAuth web application in Google.](https://support.google.com/googleapi/answer/6158849?hl=en#zippy=%2Cweb-applications).

  * Use this URL when prompted for a OAuth redirect url:

  ```
  https://<your-project-name>.oauth.midio.dev/callback
  ```
* [Save your client credentials in Midio.](#saveclientcredentials)
* Generate access token and save as Secret

## Save client credentials

### Prerequisite

Make sure you to have registered and retrieved client credentials from an application. You should have this information:

* Client ID
* Client secret
* Authorization URL
* Token URL
* Scopes

### Save in Midio

* Open `Settings` and go to the `OAuth 2.0 providers` panel
* Click `Add provider`
* Add your client configuration in the popup
  * If you have multiple scopes, you can paste them in directly if it is a list that is newline separated.

## Generate access token

### Prerequisite

Make sure you have saved a client configuration in Midio for the application you are integrating with.

### Generate and save as Secret

* Open `Settings` and go to the `Secrets` panel.
* Click `Add OAuth 2.0 provider secret`
* Select a configured provider from the list
* Enter a name for the Secret. This secret is where the access token will be saved to.
* Choose the environments where the Secret will be active in. By default it is stored in both Development and Production.
* Click `Continue` to be redirected to login with the OAuth 2.0 provider

{% hint style="success" %}
If the authorization flow is successful you will have a new secret in the table!
{% endhint %}
