File tree 4 files changed +71
-21
lines changed
4 files changed +71
-21
lines changed Original file line number Diff line number Diff line change 4
4
5
5
var settings = require ( './settings' )
6
6
, providers = require ( '../providers' )
7
+ , protocols = require ( '../protocols' )
7
8
, User = require ( '../models/User' )
8
9
;
9
10
@@ -32,14 +33,11 @@ module.exports = function (passport) {
32
33
33
34
if ( settings . providers ) {
34
35
Object . keys ( settings . providers ) . forEach ( function ( name ) {
35
- var providerConf = settings . providers [ name ]
36
+ var providerConf = settings . providers [ name ]
36
37
, provider = ( providers [ name ] ? providers [ name ] : providerConf )
37
- , protocol = provider . protocol
38
- , strategy = require ( '../protocols/' + protocol )
39
38
;
40
39
41
- provider . id = name ;
42
- passport . use ( strategy . initialize ( provider , providerConf ) ) ;
40
+ passport . use ( protocols . initialize ( name , provider , providerConf ) ) ;
43
41
} ) ;
44
42
}
45
43
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ var fs = require('fs')
11
11
* Read models directory
12
12
*/
13
13
14
- var files = fs . readdirSync ( path . join ( '.' , 'models' ) ) ;
14
+ var files = fs . readdirSync ( __dirname ) ;
15
15
16
16
17
17
/**
@@ -21,7 +21,7 @@ var files = fs.readdirSync(path.join('.', 'models'));
21
21
files . forEach ( function ( file ) {
22
22
if ( path . extname ( file ) === '.js' && file !== 'index.js' ) {
23
23
var model = path . basename ( file , '.js' ) ;
24
- module . exports [ model ] = require ( path . join ( '..' , 'models' , model ) ) ;
24
+ module . exports [ model ] = require ( path . join ( __dirname , '..' , 'models' , model ) ) ;
25
25
}
26
26
} ) ;
27
27
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Module dependencies
3
+ */
4
+
5
+ var path = require ( 'path' ) ;
6
+
7
+
8
+ /**
9
+ * Initialize
10
+ */
11
+
12
+ function initialize ( name , provider , config ) {
13
+ var strategy
14
+ , protocol = provider . protocol
15
+ ;
16
+
17
+ // try to load an officially supported provider
18
+ try {
19
+ strategy = require ( path . join ( __dirname , protocol ) ) ;
20
+ } catch ( e ) { }
21
+
22
+ // try to load a custom provider from the deployment repository
23
+ try {
24
+ strategy = require ( path . join ( cwd , 'providers' , protocol ) ) ;
25
+ } catch ( e ) {
26
+ if ( ! strategy ) {
27
+ throw new Error ( "Can't find custom protocol: " + protocol ) ;
28
+ }
29
+ }
30
+
31
+ provider . id = name ;
32
+ return strategy . initialize ( provider , config ) ;
33
+ }
34
+
35
+
36
+ /**
37
+ * Exports
38
+ */
39
+
40
+ module . exports = {
41
+ initialize : initialize
42
+ } ;
Original file line number Diff line number Diff line change 3
3
*/
4
4
5
5
var fs = require ( 'fs' )
6
+ , cwd = process . cwd ( )
6
7
, path = require ( 'path' )
7
8
, settings = require ( '../boot/settings' )
9
+ , defaultDirectory = __dirname
10
+ , customDirectory = path . join ( cwd , 'providers' )
8
11
;
9
12
10
13
11
14
/**
12
- * Read providers directory
15
+ * Load providers
13
16
*/
17
+ function loadProviders ( dir , files ) {
18
+ files . forEach ( function ( file ) {
19
+ if ( path . extname ( file ) === '.js' && file !== 'index.js' ) {
20
+ var provider = path . basename ( file , '.js' ) ;
14
21
15
- var files = fs . readdirSync ( path . join ( '.' , 'providers' ) ) ;
16
-
22
+ try {
23
+ module . exports [ provider ] = require (
24
+ path . join ( dir , provider )
25
+ ) ( settings ) ;
26
+ } catch ( e ) {
27
+ throw new Error ( "Can't load " + provider + " provider." ) ;
28
+ }
29
+ }
30
+ } ) ;
31
+ }
17
32
18
- /**
19
- * Load providers
20
- */
33
+ try {
34
+ loadProviders ( defaultDirectory , fs . readdirSync ( defaultDirectory ) ) ;
35
+ } catch ( e ) { }
21
36
22
- files . forEach ( function ( file ) {
23
- if ( path . extname ( file ) === '.js' && file !== 'index.js' ) {
24
- var provider = path . basename ( file , '.js' ) ;
25
- module . exports [ provider ] = require (
26
- path . join ( '..' , 'providers' , provider )
27
- ) ( settings ) ;
28
- }
29
- } ) ;
37
+ try {
38
+ loadProviders ( customDirectory , fs . readdirSync ( customDirectory ) ) ;
39
+ } catch ( e ) { }
You can’t perform that action at this time.
0 commit comments