Skip to content

Commit

Permalink
feat: added example call to mgmt load user
Browse files Browse the repository at this point in the history
  • Loading branch information
yosiharan committed Jan 20, 2025
1 parent d67ae96 commit 7df40f0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/webapp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func main() {
router.HandleFunc("/stepup/stepup/verify", handleStepupStepupVerify).Methods(http.MethodGet)

router.HandleFunc("/mgmt/audit/search", handleAuditSearch).Methods(http.MethodGet)
router.HandleFunc("/mgmt/user/load", handleUserLoad).Methods(http.MethodGet)

authRouter := router.Methods(http.MethodGet).Subrouter()
authRouter.Use(sdk.AuthenticationMiddleware(descopeClient.Auth, func(w http.ResponseWriter, r *http.Request, err error) {
Expand Down Expand Up @@ -158,6 +159,7 @@ func help(w http.ResponseWriter, r *http.Request) {
helpTxt += "See that you are actually logged in go to: /private \n\n"
helpTxt += "---------------------------------------------------------\n\n"
helpTxt += "Run a management audit search go to: /mgmt/audit/search \n\n"
helpTxt += "Load a user using the management API search go to: /mgmt/user/load?identifier= \n\n"
setResponse(w, http.StatusOK, helpTxt)
}

Expand Down Expand Up @@ -576,6 +578,19 @@ func handleAuditSearch(w http.ResponseWriter, r *http.Request) {
}
}

func handleUserLoad(w http.ResponseWriter, r *http.Request) {
identifier := getQuery(r, "identifier")
loadRes, err := descopeClient.Management.User().Load(context.TODO(), identifier)
if err != nil {
setError(w, err.Error())
} else {
helpTxt := "Load User Results :\n"
mr, _ := json.MarshalIndent(loadRes, "", "\t")
helpTxt += string(mr) + "\n"
setResponse(w, http.StatusOK, helpTxt)
}
}

func queryBool(r *http.Request, key string) bool {
values := r.URL.Query()[key]
return len(values) > 0
Expand Down

0 comments on commit 7df40f0

Please sign in to comment.