@@ -34,6 +34,7 @@ type StatusResp struct {
34
34
Parent string `json:"parent"`
35
35
Cookie string `json:"cookie"`
36
36
Result string `json:"result"`
37
+ ResultURL string `json:"result_url"`
37
38
} `json:"response"`
38
39
Stat string `json:"stat"`
39
40
}
@@ -241,11 +242,43 @@ func (d *DuoClient) DoStatus(txid, sid string) (auth string, err error) {
241
242
err = json .NewDecoder (res .Body ).Decode (& status )
242
243
243
244
if status .Response .Result == "SUCCESS" {
244
- auth = status .Response .Cookie
245
+ auth , err = d . DoRedirect ( status .Response .ResultURL , sid )
245
246
}
246
247
return
247
248
}
248
249
250
+ func (d * DuoClient ) DoRedirect (url string , sid string ) (string , error ) {
251
+ client := http.Client {}
252
+ statusData := "sid=" + sid
253
+ url = "https://" + d .Host + url
254
+ req , err := http .NewRequest ("POST" , url , bytes .NewReader ([]byte (statusData )))
255
+ if err != nil {
256
+ return "" , err
257
+ }
258
+
259
+ req .Header .Add ("Origin" , "https://" + d .Host )
260
+ req .Header .Add ("Content-Type" , "application/x-www-form-urlencoded" )
261
+ req .Header .Add ("X-Requested-With" , "XMLHttpRequest" )
262
+
263
+ res , err := client .Do (req )
264
+ if err != nil {
265
+ return "" , err
266
+ }
267
+ defer res .Body .Close ()
268
+
269
+ if res .StatusCode != http .StatusOK {
270
+ err = fmt .Errorf ("DUO: bad status from result_url: %d" , res .StatusCode )
271
+ return "" , err
272
+ }
273
+
274
+ var status StatusResp
275
+ err = json .NewDecoder (res .Body ).Decode (& status )
276
+ if err != nil {
277
+ return "" , err
278
+ }
279
+ return status .Response .Cookie , nil
280
+ }
281
+
249
282
// DoCallback send a POST request to the Okta callback url defined in the DuoClient
250
283
//
251
284
// The callback request requires the stateToken from Okta and a sig_response built
0 commit comments