Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

MiraiSubject/passport-osu

Repository files navigation

This project is abandoned

Please use Arctic/lucia-auth as the currently maintained alternative.

Passport-osu

Passport strategy for authenticating with osu! using the OAuth 2.0 API.

This module lets you authenticate using osu! in your Node.js applications. By plugging into Passport, osu! authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

Install

npm install passport-osu

Usage

Configure Strategy

The osu! authentication strategy authenticates users using a osu! account and OAuth 2.0 tokens. The strategy requires a verify callback, which accepts these credentials and calls done providing a user, as well as options specifying a client ID, client secret, and callback URL.

import OsuStrategy from 'passport-osu'; // or const OsuStrategy = require('passport-osu');

passport.use(new OsuStrategy({
    clientID: OSU2_CLIENT_ID,
    clientSecret: OSU2_CLIENT_SECRET,
    callbackURL: "http://localhost:8000/auth/osu/callback"
}, (accessToken, refreshToken, profile, done) => {
    User.findOrCreate({ osuId: profile.id }, function (err, user) {
    return done(err, user);
    });
}
));

If you're using this module in Javascript, please use new OsuStrategy.default(...); instead.

Authenticate Requests

Use passport.authenticate(), specifying the 'osu' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get('/auth/osu', passport.authenticate('osu'));

app.get('/auth/osu/cb', passport.authenticate('osu', { failureRedirect: '/' }), (req: Request, res: Response) => {
    res.send("Success!");
});

Examples

For a complete, working example, refer to the login example.

References

License

The MIT License