|
@@ -7,6 +7,8 @@ import (
|
|
|
"encoding/hex"
|
|
|
"fmt"
|
|
|
"net/url"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
)
|
|
@@ -80,3 +82,28 @@ func computeHmac256(message string, secret string) string {
|
|
|
h.Write([]byte(message))
|
|
|
return hex.EncodeToString(h.Sum(nil))
|
|
|
}
|
|
|
+
|
|
|
+func ParseSSOResponse(ssoData string) (SSOResponse, error) {
|
|
|
+ decodedSsoData, err := base64.StdEncoding.DecodeString(ssoData)
|
|
|
+ if err != nil {
|
|
|
+ return SSOResponse{}, err
|
|
|
+ }
|
|
|
+
|
|
|
+ queryData, err := url.ParseQuery(string(decodedSsoData))
|
|
|
+ if err != nil {
|
|
|
+ return SSOResponse{}, err
|
|
|
+ }
|
|
|
+
|
|
|
+ id, _ := strconv.Atoi(queryData.Get("external_id"))
|
|
|
+
|
|
|
+ response := SSOResponse{
|
|
|
+ ID: id,
|
|
|
+ Admin: (queryData.Get("admin") == "true"),
|
|
|
+ Moderator: (queryData.Get("moderator") == "true"),
|
|
|
+ Groups: strings.Split(queryData.Get("groups"), ","),
|
|
|
+ Username: queryData.Get("username"),
|
|
|
+ Nonce: queryData.Get("nonce"),
|
|
|
+ }
|
|
|
+
|
|
|
+ return response, nil
|
|
|
+}
|