2016-09-26 18:48:55 +00:00
|
|
|
package service
|
2016-09-05 19:50:57 +00:00
|
|
|
|
|
|
|
import (
|
2017-03-15 15:55:30 +00:00
|
|
|
"context"
|
2016-09-08 01:24:11 +00:00
|
|
|
"encoding/json"
|
2016-09-05 19:50:57 +00:00
|
|
|
"net/http"
|
2016-10-12 16:35:34 +00:00
|
|
|
"strings"
|
2017-05-09 00:43:48 +00:00
|
|
|
|
2017-06-22 19:50:45 +00:00
|
|
|
"github.com/kolide/fleet/server/sso"
|
2017-05-09 00:43:48 +00:00
|
|
|
"github.com/pkg/errors"
|
2016-09-05 19:50:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func decodeGetInfoAboutSessionRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return getInfoAboutSessionRequest{ID: id}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeGetInfoAboutSessionsForUserRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return getInfoAboutSessionsForUserRequest{ID: id}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeDeleteSessionRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return deleteSessionRequest{ID: id}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeDeleteSessionsForUserRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return deleteSessionsForUserRequest{ID: id}, nil
|
|
|
|
}
|
2016-09-08 01:24:11 +00:00
|
|
|
|
|
|
|
func decodeLoginRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
var req loginRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-10-12 16:35:34 +00:00
|
|
|
req.Username = strings.ToLower(req.Username)
|
2016-09-08 01:24:11 +00:00
|
|
|
return req, nil
|
|
|
|
}
|
2017-05-09 00:43:48 +00:00
|
|
|
|
|
|
|
func decodeInitiateSSORequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
var req initiateSSORequest
|
|
|
|
err := json.NewDecoder(r.Body).Decode(&req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeCallbackSSORequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
err := r.ParseForm()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "decode sso callback")
|
|
|
|
}
|
|
|
|
authResponse, err := sso.DecodeAuthResponse(r.FormValue("SAMLResponse"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "decoding sso callback")
|
|
|
|
}
|
|
|
|
return authResponse, nil
|
|
|
|
}
|