@@ -110,7 +110,7 @@ public async Task<LoginResultData> ContinueLogin(LoginResultData loginResultData
110
110
try
111
111
{
112
112
logger . Trace ( "2FA Continue" ) ;
113
- loginResultData = await TryContinueLogin ( host , username , password , twofacode ) ;
113
+ loginResultData = await TryLogin ( host , username , password , twofacode ) ;
114
114
115
115
if ( loginResultData . Code == LoginResultCodes . Success )
116
116
{
@@ -145,66 +145,10 @@ public async Task Logout(UriString hostAddress)
145
145
}
146
146
147
147
private async Task < LoginResultData > TryLogin (
148
- UriString host ,
149
- string username ,
150
- string password
151
- )
152
- {
153
- if ( ! nodeJsExecutablePath . HasValue )
154
- {
155
- throw new InvalidOperationException ( "nodeJsExecutablePath must be set" ) ;
156
- }
157
-
158
- if ( ! octorunScript . HasValue )
159
- {
160
- throw new InvalidOperationException ( "octorunScript must be set" ) ;
161
- }
162
-
163
- var loginTask = new OctorunTask ( taskManager . Token , nodeJsExecutablePath . Value , octorunScript . Value ,
164
- "login" , ApplicationInfo . ClientId , ApplicationInfo . ClientSecret ) ;
165
- loginTask . Configure ( processManager , workingDirectory : octorunScript . Value . Parent . Parent , withInput : true ) ;
166
- loginTask . OnStartProcess += proc =>
167
- {
168
- proc . StandardInput . WriteLine ( username ) ;
169
- proc . StandardInput . WriteLine ( password ) ;
170
- proc . StandardInput . Close ( ) ;
171
- } ;
172
-
173
- var ret = await loginTask . StartAwait ( ) ;
174
-
175
- if ( ret . IsSuccess )
176
- {
177
- return new LoginResultData ( LoginResultCodes . Success , null , host , ret . Output [ 0 ] ) ;
178
- }
179
-
180
- if ( ret . IsTwoFactorRequired )
181
- {
182
- return new LoginResultData ( LoginResultCodes . CodeRequired , "Two Factor Required." , host , ret . Output [ 0 ] ) ;
183
- }
184
-
185
- if ( ret . IsBadCredentials )
186
- {
187
- return new LoginResultData ( LoginResultCodes . Failed , "Bad credentials." , host , ret . Output [ 0 ] ) ;
188
- }
189
-
190
- if ( ret . IsLocked )
191
- {
192
- return new LoginResultData ( LoginResultCodes . LockedOut , "Account locked." , host , ret . Output [ 0 ] ) ;
193
- }
194
-
195
- if ( ret . Output . Any ( ) )
196
- {
197
- return new LoginResultData ( LoginResultCodes . Failed , "Failed." , host , ret . Output [ 0 ] ) ;
198
- }
199
-
200
- return new LoginResultData ( LoginResultCodes . Failed , "Failed." , host ) ;
201
- }
202
-
203
- private async Task < LoginResultData > TryContinueLogin (
204
148
UriString host ,
205
149
string username ,
206
150
string password ,
207
- string code
151
+ string code = null
208
152
)
209
153
{
210
154
if ( ! nodeJsExecutablePath . HasValue )
@@ -217,14 +161,20 @@ string code
217
161
throw new InvalidOperationException ( "octorunScript must be set" ) ;
218
162
}
219
163
164
+ var hasTwoFactorCode = code != null ;
165
+
166
+ var arguments = hasTwoFactorCode ? "login --twoFactor" : "login" ;
220
167
var loginTask = new OctorunTask ( taskManager . Token , nodeJsExecutablePath . Value , octorunScript . Value ,
221
- "login --twoFactor" , ApplicationInfo . ClientId , ApplicationInfo . ClientSecret ) ;
168
+ arguments , ApplicationInfo . ClientId , ApplicationInfo . ClientSecret ) ;
222
169
loginTask . Configure ( processManager , workingDirectory : octorunScript . Value . Parent . Parent , withInput : true ) ;
223
170
loginTask . OnStartProcess += proc =>
224
171
{
225
172
proc . StandardInput . WriteLine ( username ) ;
226
173
proc . StandardInput . WriteLine ( password ) ;
227
- proc . StandardInput . WriteLine ( code ) ;
174
+ if ( hasTwoFactorCode )
175
+ {
176
+ proc . StandardInput . WriteLine ( code ) ;
177
+ }
228
178
proc . StandardInput . Close ( ) ;
229
179
} ;
230
180
@@ -237,7 +187,10 @@ string code
237
187
238
188
if ( ret . IsTwoFactorRequired )
239
189
{
240
- return new LoginResultData ( LoginResultCodes . CodeFailed , "Incorrect code. Two Factor Required." , host , ret . Output [ 0 ] ) ;
190
+ var resultCodes = hasTwoFactorCode ? LoginResultCodes . CodeFailed : LoginResultCodes . CodeRequired ;
191
+ var message = hasTwoFactorCode ? "Incorrect code. Two Factor Required." : "Two Factor Required." ;
192
+
193
+ return new LoginResultData ( resultCodes , message , host , ret . Output [ 0 ] ) ;
241
194
}
242
195
243
196
if ( ret . IsBadCredentials )
0 commit comments