2019-04-24 21:52:08 +00:00
|
|
|
package duo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/duosecurity/duo_api_golang"
|
2020-03-01 00:51:11 +00:00
|
|
|
|
|
|
|
"github.com/authelia/authelia/internal/middlewares"
|
2019-04-24 21:52:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewDuoAPI create duo API instance
|
|
|
|
func NewDuoAPI(duoAPI *duoapi.DuoApi) *APIImpl {
|
|
|
|
api := new(APIImpl)
|
|
|
|
api.DuoApi = duoAPI
|
|
|
|
return api
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call call to the DuoAPI
|
2020-03-01 00:51:11 +00:00
|
|
|
func (d *APIImpl) Call(values url.Values, ctx *middlewares.AutheliaCtx) (*Response, error) {
|
2019-04-24 21:52:08 +00:00
|
|
|
_, responseBytes, err := d.DuoApi.SignedCall("POST", "/auth/v2/auth", values)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-03-01 00:51:11 +00:00
|
|
|
ctx.Logger.Tracef("Duo Push Auth Response Raw Data for %s from IP %s: %s", ctx.GetSession().Username, ctx.RemoteIP().String(), string(responseBytes))
|
|
|
|
|
2019-04-24 21:52:08 +00:00
|
|
|
var response Response
|
|
|
|
err = json.Unmarshal(responseBytes, &response)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &response, nil
|
|
|
|
}
|