passport-osu
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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({
    type: 'StrategyOptions',
    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

Package Sidebar

Install

npm i passport-osu

Weekly Downloads

27

Version

1.2.0

License

MIT

Unpacked Size

8.74 kB

Total Files

7

Last publish

Collaborators

  • miraisubject