Packages in this Guide
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
Head to your Modrinth Application Settings
Choose
+ New application to create an applicationEnter 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:3000Choose
+ Create app to create the application2
Create a ToolrinthLib Project
Create a barebones NPM project, and install the following packages:Create the entrypoint file:
- express
- @toolrinth/lib
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.js4
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.