OAuth

You can authenticate users to your osu! OAuth application using osu.js. The library doesn’t provide a plug-and-play solution for authentication, it just provides utilities specific to osu! in case you want to implement your authentication from scratch.

To do anything OAuth related, import and instantiate the Auth class.

import { Auth } from 'osu-web.js';

const auth = new Auth(clientId, clientSecret, redirectUri);

Node.js versions prior to 18 don’t have a native fetch API, so you’ll have to use a polyfill instead.

import fetch from 'node-fetch'; // Install this package
import { Auth } from 'osu-web.js';

const auth = new Auth(clientId, clientSecret, redirectUri, {
  polyfillFetch: fetch
});

Parameters

ParameterTypeOptionalDescription
clientIdnumberYour application’s OAuth client ID
clientSecretstringYour application’s OAuth client secret
redirectUristringYour application’s OAuth redirect URI
options

options

ParameterTypeOptionalDescription
polyfillFetchIn case developing with a Node.js version prior to 18, you need to pass a polyfill for the fetch API. Install node-fetch

You should avoid exposing the client secret in your source code and frontend apps. Set it as an environment variable alongside the client ID and redirect URI.

Notice that something is missing? Found a typo? Think something's incomplete? Or think that something can be explained better? Feel free to open a pull request or submit an issue on the library's Github repository .