Skip to content

Commit

Permalink
chore: cleanup + add updated metadata endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mistahj67 committed Nov 20, 2024
1 parent edec71f commit 95f9637
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
1 change: 0 additions & 1 deletion cmd/api/src/api/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ const (
URIPathVariablePlatformID = "platform_id"
URIPathVariableRoleID = "role_id"
URIPathVariableSAMLProviderID = "saml_provider_id"
URIPathVariableServiceProviderName = "saml_provider_name"
URIPathVariableTaskID = "task_id"
URIPathVariableTenantID = "tenant_id"
URIPathVariableTokenID = "token_id"
Expand Down
7 changes: 4 additions & 3 deletions cmd/api/src/api/registration/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func registerV2Auth(resources v2.Resources, routerInst *router.Router, permissio
routerInst.POST("/api/v2/logout", loginResource.Logout),

// Login path prefix matcher for SAML providers, order matters here due to PathPrefix
routerInst.POST("/api/{version}/login/saml/{saml_provider_name}/acs", managementResource.SAMLCallbackRedirect),
routerInst.GET("/api/{version}/login/saml/{saml_provider_name}/metadata", managementResource.ServeMetadata),
routerInst.PathPrefix("/api/{version}/login/saml/{saml_provider_name}", http.HandlerFunc(managementResource.SAMLLoginRedirect)),
routerInst.POST(fmt.Sprintf("/api/{version}/login/saml/{%s}/acs", api.URIPathVariableSSOProviderSlug), managementResource.SAMLCallbackRedirect),
routerInst.GET(fmt.Sprintf("/api/{version}/login/saml/{%s}/metadata", api.URIPathVariableSSOProviderSlug), managementResource.ServeMetadata),
routerInst.PathPrefix(fmt.Sprintf("/api/{version}/login/saml/{%s}", api.URIPathVariableSSOProviderSlug), http.HandlerFunc(managementResource.SAMLLoginRedirect)),

// SAML resources
routerInst.GET("/api/v2/saml", managementResource.ListSAMLProviders).RequirePermissions(permissions.AuthManageProviders),
Expand All @@ -60,6 +60,7 @@ func registerV2Auth(resources v2.Resources, routerInst *router.Router, permissio
routerInst.POST("/api/v2/sso-providers/oidc", managementResource.CreateOIDCProvider).CheckFeatureFlag(resources.DB, appcfg.FeatureOIDCSupport).RequirePermissions(permissions.AuthManageProviders),
routerInst.DELETE(fmt.Sprintf("/api/v2/sso-providers/{%s}", api.URIPathVariableSSOProviderID), managementResource.DeleteSSOProvider).RequirePermissions(permissions.AuthManageProviders),
routerInst.GET(fmt.Sprintf("/api/v2/sso/{%s}/login", api.URIPathVariableSSOProviderSlug), managementResource.SSOLoginHandler),
routerInst.GET(fmt.Sprintf("/api/v2/sso/{%s}/metadata", api.URIPathVariableSSOProviderSlug), managementResource.ServeMetadata),
routerInst.PathPrefix(fmt.Sprintf("/api/v2/sso/{%s}/callback", api.URIPathVariableSSOProviderSlug), http.HandlerFunc(managementResource.SSOCallbackHandler)),

// Permissions
Expand Down
6 changes: 3 additions & 3 deletions cmd/api/src/api/v2/auth/saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const (

// This retains support for the old saml login urls /api/{version}/login/saml/ that were added to their respective IDPs
func (s ManagementResource) SAMLLoginRedirect(response http.ResponseWriter, request *http.Request) {
ssoProviderSlug := mux.Vars(request)[api.URIPathVariableServiceProviderName]
ssoProviderSlug := mux.Vars(request)[api.URIPathVariableSSOProviderSlug]

if ssoProvider, err := s.db.GetSSOProviderBySlug(request.Context(), ssoProviderSlug); err != nil {
api.HandleDatabaseError(request, response, err)
Expand All @@ -64,7 +64,7 @@ func (s ManagementResource) SAMLLoginRedirect(response http.ResponseWriter, requ

// This retains support for the old saml acs urls /api/{version}/login/saml/ that were added to their respective IDPs
func (s ManagementResource) SAMLCallbackRedirect(response http.ResponseWriter, request *http.Request) {
ssoProviderSlug := mux.Vars(request)[api.URIPathVariableServiceProviderName]
ssoProviderSlug := mux.Vars(request)[api.URIPathVariableSSOProviderSlug]

if ssoProvider, err := s.db.GetSSOProviderBySlug(request.Context(), ssoProviderSlug); err != nil {
api.HandleDatabaseError(request, response, err)
Expand Down Expand Up @@ -190,7 +190,7 @@ func (s ManagementResource) DeleteSAMLProvider(response http.ResponseWriter, req

// Preserve old metadata endpoint
func (s ManagementResource) ServeMetadata(response http.ResponseWriter, request *http.Request) {
ssoProviderSlug := mux.Vars(request)[api.URIPathVariableServiceProviderName]
ssoProviderSlug := mux.Vars(request)[api.URIPathVariableSSOProviderSlug]

if ssoProvider, err := s.db.GetSSOProviderBySlug(request.Context(), ssoProviderSlug); err != nil {
api.HandleDatabaseError(request, response, err)
Expand Down

0 comments on commit 95f9637

Please sign in to comment.