2019-04-25 04:52:08 +07:00
|
|
|
package duo
|
|
|
|
|
2020-03-01 07:51:11 +07:00
|
|
|
import (
|
2021-12-01 10:32:58 +07:00
|
|
|
"encoding/json"
|
2020-03-01 07:51:11 +07:00
|
|
|
"net/url"
|
|
|
|
|
2020-04-05 19:37:21 +07:00
|
|
|
duoapi "github.com/duosecurity/duo_api_golang"
|
|
|
|
|
2021-08-11 08:04:35 +07:00
|
|
|
"github.com/authelia/authelia/v4/internal/middlewares"
|
2020-03-01 07:51:11 +07:00
|
|
|
)
|
2019-04-25 04:52:08 +07:00
|
|
|
|
2020-05-02 12:06:39 +07:00
|
|
|
// API interface wrapping duo api library for testing purpose.
|
2019-04-25 04:52:08 +07:00
|
|
|
type API interface {
|
2021-12-01 10:32:58 +07:00
|
|
|
Call(ctx *middlewares.AutheliaCtx, values url.Values, method string, path string) (*Response, error)
|
|
|
|
PreAuthCall(ctx *middlewares.AutheliaCtx, values url.Values) (*PreAuthResponse, error)
|
|
|
|
AuthCall(ctx *middlewares.AutheliaCtx, values url.Values) (*AuthResponse, error)
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|
|
|
|
|
2020-05-02 12:06:39 +07:00
|
|
|
// APIImpl implementation of DuoAPI interface.
|
2019-04-25 04:52:08 +07:00
|
|
|
type APIImpl struct {
|
|
|
|
*duoapi.DuoApi
|
|
|
|
}
|
|
|
|
|
2021-12-01 10:32:58 +07:00
|
|
|
// Device holds all necessary info for frontend.
|
|
|
|
type Device struct {
|
|
|
|
Capabilities []string `json:"capabilities"`
|
|
|
|
Device string `json:"device"`
|
|
|
|
DisplayName string `json:"display_name"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
SmsNextcode string `json:"sms_nextcode"`
|
|
|
|
Number string `json:"number"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Response coming from Duo API.
|
2019-04-25 04:52:08 +07:00
|
|
|
type Response struct {
|
2021-12-01 10:32:58 +07:00
|
|
|
Response json.RawMessage `json:"response"`
|
|
|
|
Code int `json:"code"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
MessageDetail string `json:"message_detail"`
|
|
|
|
Stat string `json:"stat"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// AuthResponse is a response for a authorization request.
|
|
|
|
type AuthResponse struct {
|
|
|
|
Result string `json:"result"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
StatusMessage string `json:"status_msg"`
|
|
|
|
TrustedDeviceToken string `json:"trusted_device_token"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// PreAuthResponse is a response for a preauthorization request.
|
|
|
|
type PreAuthResponse struct {
|
|
|
|
Result string `json:"result"`
|
|
|
|
StatusMessage string `json:"status_msg"`
|
|
|
|
Devices []Device `json:"devices"`
|
|
|
|
EnrollPortalURL string `json:"enroll_portal_url"`
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|