Skip to content

Commit f123552

Browse files
AshGodfreyAsh Godfrey
andauthored
Update and Refactor to include new UI (#32)
* update mfa styling * update magic link ui * update directory sync UI * update admin portal styling * refactor admin portal application * remove unneeded struct * update and refact sso application * update webhooks page --------- Co-authored-by: Ash Godfrey <[email protected]>
1 parent 3338d8e commit f123552

File tree

29 files changed

+1623
-1108
lines changed

29 files changed

+1623
-1108
lines changed

go-admin-portal-example/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Go Admin Portal Example
2-
An example Golang application demonstrating how to use the [WorkOS Golang SDK](https://github.com/workos/workos-go) so your customers can access the WorkOS Admin Portal from your application.
32

3+
An example Golang application demonstrating how to use the [WorkOS Golang SDK](https://github.com/workos/workos-go) so your customers can access the WorkOS Admin Portal from your application.
44

55
## Go Project Setup
66

77
1. Clone the example repository using your preferred secure method (HTTPS or SSH).
8+
89
```bash
910
# HTTPS
1011
git clone https://github.com/workos/go-example-applications.git
@@ -18,11 +19,13 @@ An example Golang application demonstrating how to use the [WorkOS Golang SDK](h
1819
```
1920

2021
2. Navigate to the cloned repository and to the admin portal:
22+
2123
```bash
2224
cd go-example-applications/go-admin-portal
2325
```
2426

2527
3. Obtain and make note of the following values. In the next step, these will be set as environment variables.
28+
2629
- Your [WorkOS API key](https://dashboard.workos.com/api-keys)
2730

2831
4. Create a new file called ".env" in the root of the project and add the following variables, replacing the xxx with the value from step 3:
@@ -31,6 +34,7 @@ An example Golang application demonstrating how to use the [WorkOS Golang SDK](h
3134
## Start the server
3235

3336
5. The final setup step is to start the server.
37+
3438
```bash
3539
go run main.go
3640
```
@@ -42,6 +46,7 @@ An example Golang application demonstrating how to use the [WorkOS Golang SDK](h
4246
```
4347

4448
Navigate to `localhost:8000` in your web browser to view the homepage of the Admin Portal example app. Enter the name of the new Organization to be created and the names of all of the Organization's associated domains.
49+
4550
- The Organization must be a new Organization that doesn't yet exist in your WorkOS dashboard
4651
- The domains should be entered as space-separated values, e.g. "domain1.com domain2.com domain3.com"
4752

go-admin-portal-example/main.go

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,59 @@ import (
1414
"github.com/workos/workos-go/v2/pkg/portal"
1515
)
1616

17+
func ProvisionEnterprise(w http.ResponseWriter, r *http.Request) {
18+
if err := r.ParseForm(); err != nil {
19+
log.Panic(err)
20+
}
21+
organizationDomains := []string{r.FormValue("domain")}
22+
organizationName := r.FormValue("org")
23+
24+
organization, err := organizations.CreateOrganization(context.Background(), organizations.CreateOrganizationOpts{
25+
Name: organizationName,
26+
Domains: organizationDomains,
27+
})
28+
29+
if err != nil {
30+
fmt.Println("There was an error creating this organization.")
31+
}
32+
//handle logged in
33+
tmpl := template.Must(template.ParseFiles("./static/admin_logged_in.html"))
34+
if err := tmpl.Execute(w, organization); err != nil {
35+
log.Panic(err)
36+
}
37+
}
38+
39+
func HandlePortal(w http.ResponseWriter, r *http.Request) {
40+
organizationId := r.URL.Query().Get("id")
41+
intent := r.URL.Query().Get("intent")
42+
43+
var linkIntent portal.GenerateLinkIntent
44+
switch intent {
45+
case "SSO":
46+
linkIntent = portal.SSO
47+
case "Dsync":
48+
linkIntent = portal.DSync
49+
case "AuditLogs":
50+
linkIntent = portal.AuditLogs
51+
case "LogStreams":
52+
linkIntent = portal.LogStreams
53+
default:
54+
log.Printf("Invalid intent: %s", intent)
55+
http.Error(w, "Invalid intent", http.StatusBadRequest)
56+
return
57+
}
58+
59+
link, err := portal.GenerateLink(context.Background(), portal.GenerateLinkOpts{
60+
Organization: organizationId,
61+
Intent: linkIntent,
62+
})
63+
if err != nil {
64+
log.Printf("get redirect failed: %s", err)
65+
}
66+
http.Redirect(w, r, link, http.StatusFound)
67+
}
68+
69+
1770
func main() {
1871
err := godotenv.Load()
1972
if err != nil {
@@ -26,74 +79,18 @@ func main() {
2679
APIKey string
2780
}
2881

29-
type Profile struct {
30-
First_name string
31-
Last_name string
32-
Raw_profile string
33-
}
34-
3582
flag.StringVar(&conf.Addr, "addr", ":8000", "The server addr.")
3683
flag.StringVar(&conf.APIKey, "api-key", os.Getenv("WORKOS_API_KEY"), "The WorkOS API key.")
3784

3885
log.Printf("launching admin portal demo with configuration: %+v", conf)
3986

4087
organizations.SetAPIKey(conf.APIKey)
88+
portal.SetAPIKey(conf.APIKey)
4189

4290
http.Handle("/", http.FileServer(http.Dir("./static")))
91+
http.HandleFunc("/provision-enterprise", ProvisionEnterprise)
92+
http.HandleFunc("/admin-portal", HandlePortal)
4393

44-
http.HandleFunc("/provision-enterprise", func(w http.ResponseWriter, r *http.Request) {
45-
if err := r.ParseForm(); err != nil {
46-
log.Panic(err)
47-
}
48-
organizationDomains := []string{r.FormValue("domain")}
49-
organizationName := r.FormValue("org")
50-
51-
organization, err := organizations.CreateOrganization(context.Background(), organizations.CreateOrganizationOpts{
52-
Name: organizationName,
53-
Domains: organizationDomains,
54-
})
55-
56-
if err != nil {
57-
fmt.Println("There was an error creating this organization.")
58-
}
59-
60-
//handle logged in
61-
tmpl := template.Must(template.ParseFiles("./static/admin_logged_in.html"))
62-
raw_profile := "profile"
63-
this_profile := Profile{"first", "last", raw_profile}
64-
if err := tmpl.Execute(w, this_profile); err != nil {
65-
log.Panic(err)
66-
}
67-
68-
http.HandleFunc("/dsync-admin-portal", func(w http.ResponseWriter, r *http.Request) {
69-
portal.SetAPIKey(conf.APIKey)
70-
organizationId := organization.ID
71-
// Generate an SSO Adnim Portal Link using the Organization ID from above.
72-
link, err := portal.GenerateLink(context.Background(), portal.GenerateLinkOpts{
73-
Organization: organizationId,
74-
Intent: "dsync",
75-
})
76-
if err != nil {
77-
log.Printf("get redirect failed: %s", err)
78-
}
79-
http.Redirect(w, r, link, http.StatusFound)
80-
})
81-
82-
http.HandleFunc("/sso-admin-portal", func(w http.ResponseWriter, r *http.Request) {
83-
portal.SetAPIKey(conf.APIKey)
84-
organizationId := organization.ID
85-
// Generate an SSO Adnim Portal Link using the Organization ID from above.
86-
link, err := portal.GenerateLink(context.Background(), portal.GenerateLinkOpts{
87-
Organization: organizationId,
88-
Intent: "sso",
89-
})
90-
if err != nil {
91-
log.Printf("get redirect failed: %s", err)
92-
}
93-
http.Redirect(w, r, link, http.StatusFound)
94-
})
95-
96-
})
9794

9895
if err := http.ListenAndServe(conf.Addr, nil); err != nil {
9996
log.Panic(err)
Lines changed: 85 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,88 @@
11
<html>
2-
<head>
3-
<link rel="stylesheet" href="/stylesheets/style.css">
4-
</head>
5-
<body class="container_success">
6-
<div class="logged_in_nav">
7-
<div class="flex">
8-
<img src="/images/workos_logo_new.png" alt="workos logo">
9-
</div>
10-
</div>
11-
<div class='flex'>
12-
<div class="logged_in_div_left">
13-
<div>
14-
<h1>Your app,</h1>
15-
<h2 class="home-hero-gradient">Enterprise Ready</h2>
16-
</div>
17-
<div>
18-
<a href="https://workos.com/" target="_blank"><button class='button'>WorkOS</button></a>
19-
<a href="https://workos.com/docs" target="_blank"><button class='button'>Documentation</button></a>
20-
<a href="https://workos.com/docs/reference" target="_blank"><button class='button'>API Reference</button></a>
21-
<a href="https://workos.com/blog" target="_blank"><button class='button'>Blog</button></a>
2+
<head>
3+
<link rel="stylesheet" href="/stylesheets/style.css" />
4+
</head>
225

23-
</div>
24-
</div>
25-
<div class="logged_in_div_right">
26-
<div class="flex_column">
27-
<h2>Which Admin Portal would you like to launch?</h2>
28-
<div class="flex">
29-
<div>
30-
<a href="/sso-admin-portal"><button class='button dsync_button'>Launch SSO</button></a>
31-
</div>
32-
<div>
33-
<a href="/dsync-admin-portal"><button class='button dsync_button'>Launch Directory Sync</button></a>
34-
</div>
35-
</div>
36-
</div>
37-
</div>
6+
<body class="container_success">
7+
<div class="logged_in_nav">
8+
<div class="flex">
9+
<div>
10+
<img src="/images/workos_logo_new.png" alt="workos logo" />
11+
</div>
12+
</div>
13+
<div>
14+
<a href="https://workos.com/docs" target="_blank"
15+
><button class="button nav-item">Documentation</button></a
16+
>
17+
<a href="https://workos.com/docs/reference" target="_blank"
18+
><button class="button nav-item">API Reference</button></a
19+
>
20+
<a href="https://workos.com/blog" target="_blank"
21+
><button class="button nav-item blog-nav-button">Blog</button></a
22+
>
23+
<a href="https://workos.com/" target="_blank"
24+
><button class="button button-outline">WorkOS</button></a
25+
>
26+
</div>
27+
</div>
28+
<div class="flex">
29+
<div class="logged_in_div_right">
30+
<div class="flex_column">
31+
<h2>Which Admin Portal would you like to launch?</h2>
32+
<div class="flex">
33+
<table class="width-65vw">
34+
<tr>
35+
<th>Intent</th>
36+
<th>Create New Session</th>
37+
</tr>
38+
<tr>
39+
<td class="ta-left">SSO</td>
40+
<td>
41+
<a
42+
class="button button-outline"
43+
href="/admin-portal?id={{ .ID }}&intent=SSO"
44+
><i icon-name="settings-2" class="stroke_width=1"></i
45+
></a>
46+
</td>
47+
</tr>
48+
<tr>
49+
<td class="ta-left">Directory Sync</td>
50+
<td>
51+
<a
52+
class="button button-outline"
53+
href="/admin-portal?id={{ .ID }}&intent=DSync"
54+
><i icon-name="settings-2" class="stroke_width=1"></i
55+
></a>
56+
</td>
57+
</tr>
58+
<tr>
59+
<td class="ta-left">Audit Logs</td>
60+
<td>
61+
<a
62+
class="button button-outline"
63+
href="/admin-portal?id={{ .ID }}&intent=AuditLogs"
64+
><i icon-name="settings-2" class="stroke_width=1"></i
65+
></a>
66+
</td>
67+
</tr>
68+
<tr>
69+
<td class="ta-left">Log Streams</td>
70+
<td>
71+
<a
72+
class="button button-outline"
73+
href="/admin-portal?id={{ .ID }}&intent=LogStreams"
74+
><i icon-name="settings-2" class="stroke_width=1"></i
75+
></a>
76+
</td>
77+
</tr>
78+
</table>
79+
</div>
3880
</div>
39-
</body>
40-
</html>
81+
</div>
82+
</div>
83+
</body>
84+
<script src="https://unpkg.com/lucide@latest"></script>
85+
<script>
86+
lucide.createIcons();
87+
</script>
88+
</html>

0 commit comments

Comments
 (0)