Overview
Use the providers.json
file to configure third-party login using loopback-component-passport. This file contains settings for each third-party authorization provider, in provider and provider-link objects (for example, google-login and google-link).
To load the configuration, add code such as the following to server.js
:
/server/server.js
var loopbackPassport = require('loopback-component-passport'); var PassportConfigurator = loopbackPassport.PassportConfigurator; var passportConfigurator = new PassportConfigurator(app); // Build the providers/passport config var config = {}; try { config = require('../providers.json'); } catch (err) { console.trace(err); process.exit(1); // fatal }
Example providers.json
Below is the providers.template.json file provided with loopback-example-passport.
Provider property reference
Common properties
Property | Type | Description | Example | Default |
---|---|---|---|---|
provider | String | Identifies the provider; can be any identifier string. | "facebook" | |
module | String | Node module to use | "passport-facebook" | |
authScheme | String | Default is OAuth 2.0 | "oauth" | oAuth 2.0 |
strategy | String | The name of passport strategy | "OAuth2Strategy" | |
authPath | String | The local URL for authentication | "/auth/facebook" | /auth/<provider> |
link | Boolean | True if you want to link accounts. | true | false |
OAuth 1.0
Property | Type | Description | Example |
---|---|---|---|
consumerKey | String | A value used by the Consumer to identify itself to the Service Provider | |
consumerSecret | String | A secret used by the Consumer to establish ownership of the Consumer Key | |
callbackURL | String | A URL the Service Provider will use to redirect the User back to the Consumer when Obtaining User Authorization is complete | "http://localhost:3000/auth/facebook/callback" |
callbackPath | String | A local URL to mount the callback page | "/auth/facebook/callback" |
successRedirect | String | A local URL for the success login | "/auth/account" |
scope | Array of String | An array of oAuth 1.0 scopes | ["email"] |
OAuth 2
Google and Facebook
Property | Type | Description | Example |
---|---|---|---|
clientID | String | The client identifier issued to the client during the registration process | |
clientSecret | String | The client secret | |
callbackURL | String | oAuth 2.0 callback URL | "http://localhost:3000/auth/facebook/callback" |
callbackPath | String | A local URL to mount the callback page | "/auth/facebook/callback" |
successRedirect | String | A local URL for the success login | "/auth/account" |
scope | Array of String | An array of oAuth 2.0 scopes | ["email"] |
Local
Property | Type | Description | Example | Default |
---|---|---|---|---|
usernameField | String | The field name for username on the login form | "user" | username |
passwordField | String | The field name for password on the login form | "pass" | password |
successRedirect | String | A local URL for the success login | "/auth/account" |