|
@@ -51,6 +51,28 @@ func generateSSORequestURL(config SsoConfig) string {
|
|
|
return ssoURL
|
|
|
}
|
|
|
|
|
|
+// GenerateSSO - Generate the sso and sig for an sso request
|
|
|
+func GenerateSSO(nonce string, returnEndpoint, secret string) (string, string) {
|
|
|
+ // Build the query string payload
|
|
|
+ payload := fmt.Sprintf("nonce=%s&return_sso_url=%s", nonce, returnEndpoint)
|
|
|
+
|
|
|
+ // Base64 encode the payload
|
|
|
+ base64Payload := base64.StdEncoding.EncodeToString([]byte(payload))
|
|
|
+
|
|
|
+ // Urlencode the
|
|
|
+ URLEncodedPayload := url.QueryEscape(base64Payload)
|
|
|
+
|
|
|
+ // Get a hex signature for this payload with the sso secret
|
|
|
+ hexSignature := computeHmac256(base64Payload, secret)
|
|
|
+
|
|
|
+ return URLEncodedPayload, hexSignature
|
|
|
+}
|
|
|
+
|
|
|
+// GetSSOUrl - Generate the sso enpodint url give the domain, sso and sig
|
|
|
+func GetSSOUrl(endpoint, sso, sig string) string {
|
|
|
+ return fmt.Sprintf("%s/session/sso_provider?sso=%s&sig=%s", endpoint, sso, sig)
|
|
|
+}
|
|
|
+
|
|
|
// Create a hex signature from a message and secret
|
|
|
func computeHmac256(message string, secret string) string {
|
|
|
key := []byte(secret)
|