@@ -47,7 +47,7 @@ class SSPI extends AuthProvider {
47
47
}
48
48
}
49
49
50
- var SSIPAuthenticate = function (
50
+ function SSIPAuthenticate (
51
51
self ,
52
52
username ,
53
53
password ,
@@ -57,111 +57,73 @@ var SSIPAuthenticate = function(
57
57
options ,
58
58
callback
59
59
) {
60
- // Build Authentication command to send to MongoDB
61
- var command = {
62
- saslStart : 1 ,
63
- mechanism : 'GSSAPI' ,
64
- payload : '' ,
65
- autoAuthorize : 1
66
- } ;
67
-
68
- // Create authenticator
69
- var mongo_auth_process = new MongoAuthProcess (
60
+ const authProcess = new MongoAuthProcess (
70
61
connection . host ,
71
62
connection . port ,
72
63
gssapiServiceName ,
73
64
options
74
65
) ;
75
66
76
- // Execute first sasl step
77
- server (
78
- connection ,
79
- new Query ( self . bson , '$external.$cmd' , command , {
67
+ function authCommand ( command , authCb ) {
68
+ const query = new Query ( self . bson , '$external.$cmd' , command , {
80
69
numberToSkip : 0 ,
81
70
numberToReturn : 1
82
- } ) ,
83
- function ( err , r ) {
71
+ } ) ;
72
+
73
+ server ( connection , query , authCb ) ;
74
+ }
75
+
76
+ authProcess . init ( username , password , err => {
77
+ if ( err ) return callback ( err , false ) ;
78
+
79
+ authProcess . transition ( '' , ( err , payload ) => {
84
80
if ( err ) return callback ( err , false ) ;
85
- var doc = r . result ;
86
81
87
- mongo_auth_process . init ( username , password , function ( err ) {
88
- if ( err ) return callback ( err ) ;
82
+ const command = {
83
+ saslStart : 1 ,
84
+ mechanism : 'GSSAPI' ,
85
+ payload,
86
+ autoAuthorize : 1
87
+ } ;
89
88
90
- mongo_auth_process . transition ( doc . payload , function ( err , payload ) {
91
- if ( err ) return callback ( err ) ;
89
+ authCommand ( command , ( err , result ) => {
90
+ if ( err ) return callback ( err , false ) ;
91
+ const doc = result . result ;
92
92
93
- // Perform the next step against mongod
94
- var command = {
93
+ authProcess . transition ( doc . payload , ( err , payload ) => {
94
+ if ( err ) return callback ( err , false ) ;
95
+ const command = {
95
96
saslContinue : 1 ,
96
97
conversationId : doc . conversationId ,
97
- payload : payload
98
+ payload
98
99
} ;
99
100
100
- // Execute the command
101
- server (
102
- connection ,
103
- new Query ( self . bson , '$external.$cmd' , command , {
104
- numberToSkip : 0 ,
105
- numberToReturn : 1
106
- } ) ,
107
- function ( err , r ) {
101
+ authCommand ( command , ( err , result ) => {
102
+ if ( err ) return callback ( err , false ) ;
103
+ const doc = result . result ;
104
+
105
+ authProcess . transition ( doc . payload , ( err , payload ) => {
108
106
if ( err ) return callback ( err , false ) ;
109
- var doc = r . result ;
110
-
111
- mongo_auth_process . transition ( doc . payload , function ( err , payload ) {
112
- if ( err ) return callback ( err ) ;
113
-
114
- // Perform the next step against mongod
115
- var command = {
116
- saslContinue : 1 ,
117
- conversationId : doc . conversationId ,
118
- payload : payload
119
- } ;
120
-
121
- // Execute the command
122
- server (
123
- connection ,
124
- new Query ( self . bson , '$external.$cmd' , command , {
125
- numberToSkip : 0 ,
126
- numberToReturn : 1
127
- } ) ,
128
- function ( err , r ) {
129
- if ( err ) return callback ( err , false ) ;
130
- var doc = r . result ;
131
-
132
- mongo_auth_process . transition ( doc . payload , function ( err , payload ) {
133
- // Perform the next step against mongod
134
- var command = {
135
- saslContinue : 1 ,
136
- conversationId : doc . conversationId ,
137
- payload : payload
138
- } ;
139
-
140
- // Execute the command
141
- server (
142
- connection ,
143
- new Query ( self . bson , '$external.$cmd' , command , {
144
- numberToSkip : 0 ,
145
- numberToReturn : 1
146
- } ) ,
147
- function ( err , r ) {
148
- if ( err ) return callback ( err , false ) ;
149
- var doc = r . result ;
150
-
151
- if ( doc . done ) return callback ( null , true ) ;
152
- callback ( new Error ( 'Authentication failed' ) , false ) ;
153
- }
154
- ) ;
155
- } ) ;
156
- }
157
- ) ;
107
+ const command = {
108
+ saslContinue : 1 ,
109
+ conversationId : doc . conversationId ,
110
+ payload
111
+ } ;
112
+
113
+ authCommand ( command , ( err , response ) => {
114
+ if ( err ) return callback ( err , false ) ;
115
+
116
+ authProcess . transition ( null , err => {
117
+ if ( err ) return callback ( err , null ) ;
118
+ callback ( null , response ) ;
119
+ } ) ;
158
120
} ) ;
159
- }
160
- ) ;
121
+ } ) ;
122
+ } ) ;
161
123
} ) ;
162
124
} ) ;
163
- }
164
- ) ;
165
- } ;
125
+ } ) ;
126
+ } ) ;
127
+ }
166
128
167
129
module . exports = SSPI ;
0 commit comments