0.1.1 • Published 5 years ago

passport-nextcloud v0.1.1

Weekly downloads
2
License
MIT
Repository
-
Last release
5 years ago

NOT TESTED - WIP - USE AT YOUR OWN RISK

passport-nextcloud

Based on passport-gitlab2.

npm version

Passport strategy for authenticating with Nextcloud using the OAuth2 authentication provider service.

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

Install

$ npm install passport-nextcloud

Usage

Before using the OAuth2 authentication provider service, you have register a new application in the admin security settings. nextcloud will then issue an application ID and a secret, which need to be provided to the strategy. You will also need to configure a redirect URI which matches the route in your application.

Configure Strategy

The Nextcloud authentication strategy authenticates uses a Nextcloud account and OAuth 2.0 tokens. The app ID and secret obtained when creating an application are supplied as options when creating the strategy. The strategy also requires a verify callback, which receives the access token and optional refresh token, as well as profile which contains the authenticated user's Nextcloud profile. The verify callback must call cb providing a user to complete authentication.

passport.use(new NextcloudStrategy({
    clientID: NEXTCLOUD_APP_ID,
    clientSecret: NEXTCLOUD_APP_SECRET,
    callbackURL: "http://localhost:3000/auth/nextcloud/callback"
  },
  function(accessToken, refreshToken, profile, cb) {
    User.findOrCreate({gitlabId: profile.id}, function (err, user) {
      return cb(err, user);
    });
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

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

app.get('/auth/nextcloud/callback',
  passport.authenticate('nextcloud', {
    failureRedirect: '/login'
  }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
  });

Code style

This module uses the Google JavaScript Code-Style and enforces it using JSCS as additional linter beneath JSHint. These measures ensuring a high level of code quality and easy maintainability of it. You can test if your changes comply with the code style by executing:

$ make lint

Tests

The test suite is located in the test/ directory. All new features are expected to have corresponding test cases. Ensure that the complete test suite passes by executing:

$ make test

Coverage

The test suite covers 100% of the code base. All new feature development is expected to maintain that level. Coverage reports can be viewed by executing:

$ make coverage-view

License

The MIT License

Copyright (c) 2019 Sebastian Hugentobler sebastian@vanwa.ch