Skip to content

Latest commit

 

History

History
78 lines (60 loc) · 2.37 KB

README.md

File metadata and controls

78 lines (60 loc) · 2.37 KB

Meteor DDP Login Handler

Test suite CodeQL built with Meteor GitHub

Authenticate a remote DDP connect using an accessToken and a custom OAuth2 service.

This allows to make calls via DDP connection in behalf of a user, that is registered on a remote Accounts server.

Usage

The handler needs to make a call to your OAuth2 server's identity URL (the one that is used to retrieve user credentials after the workflow has completed successfully).

If the OAuth2 server responds with data (ususally an id and login or username field) it will add the user to the users collection and also sets the DDP session's user to it.

Example setup:

/* global ServiceConfiguration */
import { Meteor } from 'meteor/meteor'
import { Accounts } from 'meteor/accounts-base'
import { HTTP } from 'meteor/http'
import {
  defaultDDPLoginName,
  getOAuthDDPLoginHandler
} from 'meteor/leaonline:ddp-login-handler'

Meteor.startup(() => {
  setupOAuth()
})

function setupOAuth () {
  const { oauth } = Meteor.settings
  
  ServiceConfiguration.configurations.upsert(
    { service: 'lea' },
    {
      $set: {
        loginStyle: 'popup',
        clientId: oauth.clientId,
        secret: oauth.secret,
        dialogUrl: oauth.dialogUrl,
        accessTokenUrl: oauth.accessTokenUrl,
        identityUrl: oauth.identityUrl,
        redirectUrl: oauth.redirectUrl
      }
    }
  )

  const loginHandler = getOAuthDDPLoginHandler({
    identityUrl: oauth.identityUrl,
    httpGet: (url, requestOptions) => HTTP.get(url, requestOptions),
    debug: console.debug
  })

  Accounts.registerLoginHandler(defaultDDPLoginName, loginHandler)
}

Development, running tests

To run the tests you can use the following line on your terminal:

$ TEST_WATCH=1 TEST_CLIENT=0 meteor test-packages ./ --driver-package meteortesting:mocha

LICENSE

MIT, see LICENSE file