@@ -34,6 +34,7 @@ type StatusResp struct {
3434 Parent string `json:"parent"`
3535 Cookie string `json:"cookie"`
3636 Result string `json:"result"`
37+ ResultURL string `json:"result_url"`
3738 } `json:"response"`
3839 Stat string `json:"stat"`
3940}
@@ -241,11 +242,43 @@ func (d *DuoClient) DoStatus(txid, sid string) (auth string, err error) {
241242 err = json .NewDecoder (res .Body ).Decode (& status )
242243
243244 if status .Response .Result == "SUCCESS" {
244- auth = status .Response .Cookie
245+ auth , err = d . DoRedirect ( status .Response .ResultURL , sid )
245246 }
246247 return
247248}
248249
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+
249282// DoCallback send a POST request to the Okta callback url defined in the DuoClient
250283//
251284// The callback request requires the stateToken from Okta and a sig_response built
0 commit comments