2019-04-25 04:52:08 +07:00
|
|
|
package duo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/url"
|
|
|
|
|
2020-04-05 19:37:21 +07:00
|
|
|
duoapi "github.com/duosecurity/duo_api_golang"
|
2020-03-01 07:51:11 +07:00
|
|
|
|
2021-08-11 08:04:35 +07:00
|
|
|
"github.com/authelia/authelia/v4/internal/middlewares"
|
2019-04-25 04:52:08 +07:00
|
|
|
)
|
|
|
|
|
2020-05-02 12:06:39 +07:00
|
|
|
// NewDuoAPI create duo API instance.
|
2019-04-25 04:52:08 +07:00
|
|
|
func NewDuoAPI(duoAPI *duoapi.DuoApi) *APIImpl {
|
|
|
|
api := new(APIImpl)
|
|
|
|
api.DuoApi = duoAPI
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2019-04-25 04:52:08 +07:00
|
|
|
return api
|
|
|
|
}
|
|
|
|
|
2020-05-02 12:06:39 +07:00
|
|
|
// Call call to the DuoAPI.
|
2020-03-01 07:51:11 +07:00
|
|
|
func (d *APIImpl) Call(values url.Values, ctx *middlewares.AutheliaCtx) (*Response, error) {
|
2020-05-06 02:35:32 +07:00
|
|
|
var response Response
|
2019-04-25 04:52:08 +07:00
|
|
|
|
2020-05-06 02:35:32 +07:00
|
|
|
_, responseBytes, err := d.DuoApi.SignedCall("POST", "/auth/v2/auth", values)
|
2019-04-25 04:52:08 +07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-03-01 07:51:11 +07: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-25 04:52:08 +07:00
|
|
|
err = json.Unmarshal(responseBytes, &response)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2019-04-25 04:52:08 +07:00
|
|
|
return &response, nil
|
|
|
|
}
|