Skip to main content

Packages in this Guide

Express v5.2.1

for the web server
@toolrinth/lib v1.1.0

for Modrinth OAuth
This guide does not cover token storage methods (cookies, localStorage, etc). It also does not cover security measures, such as state. It is expected that you know how to handle the data you receive. This guide is focused on the nuances of the ToolrinthLib OAuth2 client.

1

Create a Modrinth OAuth Application

To interact with Modrinth’s OAuth API, you need to create an application in your user application settings
Choose + New application to create an application
Enter an Application name. We’ll use “ToolrinthLib Tutorial” for this guide.
From the list of scopes, choose the following:
  • Read user data
  • Read projects
  • Read versions
  • Read organizations
Enter the redirect url: http://localhost:3000
Choose + Create app to create the application
2

Create a ToolrinthLib Project

Create a barebones NPM project, and install the following packages:
  • express
  • @toolrinth/lib
Create the entrypoint file:
3

Set up the Project

First things first, we need to create our Express server and the ToolrinthLib OAuth2 client. We also need to listen for GET requests on the root path (/)Start the webserver with node index.js
4

Listen for Requests

Now that our webserver is online, we need to check whether or not incoming requests contain an authorization code, and act accordingly.
5

Obtain an Access Token

One you have an authorization code, you can use OAuth2.Client#exchangeCode() to obtain an access token for use with the Modrinth API.