1.2.0 • Published 2 years ago

passport-osu v1.2.0

Weekly downloads
8
License
MIT
Repository
github
Last release
2 years ago

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