Meteor DDP Login Handler
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:
1/* global ServiceConfiguration */ 2import { Meteor } from 'meteor/meteor' 3import { Accounts } from 'meteor/accounts-base' 4import { HTTP } from 'meteor/http' 5import { 6 defaultDDPLoginName, 7 getOAuthDDPLoginHandler 8} from 'meteor/leaonline:ddp-login-handler' 9 10Meteor.startup(() => { 11 setupOAuth() 12}) 13 14function setupOAuth () { 15 const { oauth } = Meteor.settings 16 17 ServiceConfiguration.configurations.upsert( 18 { service: 'lea' }, 19 { 20 $set: { 21 loginStyle: 'popup', 22 clientId: oauth.clientId, 23 secret: oauth.secret, 24 dialogUrl: oauth.dialogUrl, 25 accessTokenUrl: oauth.accessTokenUrl, 26 identityUrl: oauth.identityUrl, 27 redirectUrl: oauth.redirectUrl 28 } 29 } 30 ) 31 32 const loginHandler = getOAuthDDPLoginHandler({ 33 identityUrl: oauth.identityUrl, 34 httpGet: (url, requestOptions) => HTTP.get(url, requestOptions), 35 debug: console.debug 36 }) 37 38 Accounts.registerLoginHandler(defaultDDPLoginName, loginHandler) 39}
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