Browse Source

Intial set of fixes

thisnthat 5 years ago
parent
commit
b529aa657d
2 changed files with 9 additions and 9 deletions
  1. 6 6
      discourse.go
  2. 3 3
      sso.go

+ 6 - 6
discourse.go

@@ -3,10 +3,10 @@ package discourse
 import "github.com/google/uuid"
 
 type SsoConfig struct {
-	endpoint       string
-	returnEndpoint string
-	secret         string
-	uuid           uuid.UUID
+	Endpoint       string
+	ReturnEndpoint string
+	Secret         string
+	Uuid           uuid.UUID
 }
 
 func GetSSORequestURL(config SsoConfig) string {
@@ -16,8 +16,8 @@ func GetSSORequestURL(config SsoConfig) string {
 }
 
 // ValidateSsoResponse - Validate the signature on the sso response
-func ValidateSsoResponse(config SsoConfig, sso string, sig string) bool {
-	ssoDataSig := computeHmac256(sso, config.secret)
+func ValidateSsoResponse(sso, sig, secret string) bool {
+	ssoDataSig := computeHmac256(sso, secret)
 
 	return sig == ssoDataSig
 }

+ 3 - 3
sso.go

@@ -11,7 +11,7 @@ import (
 
 func generateSSORequestURL(config SsoConfig) string {
 	// Build the query string payload
-	payload := fmt.Sprintf("nonce=%s&return_sso_url=%s", config.uuid, config.returnEndpoint)
+	payload := fmt.Sprintf("nonce=%s&return_sso_url=%s", config.Uuid, config.ReturnEndpoint)
 
 	// Base64 encode the payload
 	base64Payload := base64.StdEncoding.EncodeToString([]byte(payload))
@@ -20,9 +20,9 @@ func generateSSORequestURL(config SsoConfig) string {
 	URLEncodedPayload := url.QueryEscape(base64Payload)
 
 	// Get a hex signature for this payload with the sso secret
-	hexSignature := computeHmac256(base64Payload, config.secret)
+	hexSignature := computeHmac256(base64Payload, config.Secret)
 
-	ssoURL := fmt.Sprintf("%s?sso=%s&sig=%s", config.endpoint, URLEncodedPayload, hexSignature)
+	ssoURL := fmt.Sprintf("%s?sso=%s&sig=%s", config.Endpoint, URLEncodedPayload, hexSignature)
 
 	return ssoURL
 }