Skip to content

Commit aae61a9

Browse files
Merge pull request #543 from USACE/develop
Develop to Stable - identity endpoint
2 parents eacff56 + db788e7 commit aae61a9

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

api/handlers/helpers.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package handlers
22

33
import (
44
"errors"
5+
"net/http"
6+
"strings"
57

68
"github.com/USACE/cumulus-api/api/middleware"
79
"github.com/google/uuid"
@@ -15,3 +17,51 @@ func GetSub(c echo.Context) (*uuid.UUID, error) {
1517
}
1618
return userInfo.Sub, nil
1719
}
20+
21+
// GetIdentityProviderConfiguration returns the Keycloak configuration based on the auth environment and realm
22+
func GetIdentityProviderConfiguration(authEnv string, c echo.Context) error {
23+
24+
// Convert the authEnv to lowercase to make the comparison case-insensitive
25+
authEnv = strings.ToLower(authEnv)
26+
27+
// Set the base URL for Keycloak depending on the environment
28+
var keycloakHost string
29+
realm := "cwbi" // Set the realm as a variable
30+
31+
// Determine the Keycloak host based on the authEnv passed
32+
switch authEnv {
33+
// ----------------------------
34+
// Satisfy local mocking
35+
case "mock":
36+
keycloakHost = "http://localhost"
37+
// ----------------------------
38+
// Castle Cloud auth servers
39+
case "develop":
40+
keycloakHost = "https://develop-auth.corps.cloud"
41+
realm = "water"
42+
case "stable":
43+
keycloakHost = "https://auth.corps.cloud"
44+
realm = "water"
45+
// ----------------------------
46+
// CWBI auth servers
47+
case "dev":
48+
keycloakHost = "https://identityc-test.cwbi.us"
49+
case "test":
50+
keycloakHost = "https://identityc-test.cwbi.us"
51+
case "prod":
52+
keycloakHost = "https://identityc.sec.usace.army.mil"
53+
default:
54+
return c.JSON(http.StatusBadRequest, map[string]string{
55+
"error": "Invalid auth environment: " + authEnv,
56+
})
57+
}
58+
59+
// Prepare the configuration as a map of string keys and values
60+
config := map[string]string{
61+
"token_endpoint": keycloakHost + "/auth/realms/" + realm + "/protocol/openid-connect/token",
62+
"well_known_endpoint": keycloakHost + "/auth/realms/" + realm + "/.well-known/openid-configuration",
63+
}
64+
65+
// Return the configuration as a JSON response
66+
return c.JSON(http.StatusOK, config)
67+
}

api/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ func main() {
9393
})
9494
})
9595

96+
// Identity Provider Configuration Route
97+
public.GET("/identity-provider/configuration", func(c echo.Context) error {
98+
return handlers.GetIdentityProviderConfiguration(cfg.AuthEnvironment, c)
99+
})
100+
96101
// Proxy to pg_featureserv
97102
features := public.Group("/features")
98103
features.Use(middleware.PgFeatureservProxy(cfg.PgFeatureservUrl))

0 commit comments

Comments
 (0)