Skip to content

Commit 785571b

Browse files
authored
Go update sdk versions (#34)
* updated SDK to v3 in example apps * removing files that should not have been added * adding .gitignore files to each example application
1 parent 356fd9c commit 785571b

File tree

24 files changed

+212
-194
lines changed

24 files changed

+212
-194
lines changed

go-admin-portal-example/.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories (remove the comment below to include it)
15+
# vendor/
16+
17+
# Environment Variables
18+
*.env

go-admin-portal-example/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ go 1.16
55
require (
66
github.com/google/go-querystring v1.1.0 // indirect
77
github.com/joho/godotenv v1.5.1
8-
github.com/workos/workos-go/v2 v2.1.0
8+
github.com/workos/workos-go/v3 v3.1.0
99
)

go-admin-portal-example/go.sum

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@ github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO
66
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
77
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
88
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
9-
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
10-
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
119
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
1210
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
1311
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1412
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1513
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1614
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
1715
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
18-
github.com/workos/workos-go/v2 v2.0.2 h1:7CLsldo9Bqdyo+ikJO7bTnvVoD+U6GkqHoBfKHpQZZg=
19-
github.com/workos/workos-go/v2 v2.0.2/go.mod h1:5702ja1jMGArYgqS0lCowTNltHmYCJ8Uf4Iu2e+VNyw=
20-
github.com/workos/workos-go/v2 v2.1.0 h1:eZotGtDL1tw6Oq9CazlR+AMg//eBDX23bdfT616Pf8o=
21-
github.com/workos/workos-go/v2 v2.1.0/go.mod h1:5702ja1jMGArYgqS0lCowTNltHmYCJ8Uf4Iu2e+VNyw=
16+
github.com/workos/workos-go/v3 v3.1.0 h1:DHDQ5PWWsfie9ZjDw4xezVkNV5xEKAH21vMGQpc1DSo=
17+
github.com/workos/workos-go/v3 v3.1.0/go.mod h1:SUdYqICB2LG2G2UMMNI2EcBYX9OdpzgpNYlW6k0JML4=
2218
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
2319
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2420
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=

go-admin-portal-example/main.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"text/template"
1111

1212
"github.com/joho/godotenv"
13-
"github.com/workos/workos-go/v2/pkg/organizations"
14-
"github.com/workos/workos-go/v2/pkg/portal"
13+
"github.com/workos/workos-go/v3/pkg/organizations"
14+
"github.com/workos/workos-go/v3/pkg/portal"
1515
)
1616

1717
func ProvisionEnterprise(w http.ResponseWriter, r *http.Request) {
@@ -39,7 +39,7 @@ func ProvisionEnterprise(w http.ResponseWriter, r *http.Request) {
3939
func HandlePortal(w http.ResponseWriter, r *http.Request) {
4040
organizationId := r.URL.Query().Get("id")
4141
intent := r.URL.Query().Get("intent")
42-
42+
4343
var linkIntent portal.GenerateLinkIntent
4444
switch intent {
4545
case "SSO":
@@ -55,18 +55,17 @@ func HandlePortal(w http.ResponseWriter, r *http.Request) {
5555
http.Error(w, "Invalid intent", http.StatusBadRequest)
5656
return
5757
}
58-
58+
5959
link, err := portal.GenerateLink(context.Background(), portal.GenerateLinkOpts{
6060
Organization: organizationId,
61-
Intent: linkIntent,
61+
Intent: linkIntent,
6262
})
6363
if err != nil {
6464
log.Printf("get redirect failed: %s", err)
6565
}
6666
http.Redirect(w, r, link, http.StatusFound)
6767
}
6868

69-
7069
func main() {
7170
err := godotenv.Load()
7271
if err != nil {
@@ -91,7 +90,6 @@ func main() {
9190
http.HandleFunc("/provision-enterprise", ProvisionEnterprise)
9291
http.HandleFunc("/admin-portal", HandlePortal)
9392

94-
9593
if err := http.ListenAndServe(conf.Addr, nil); err != nil {
9694
log.Panic(err)
9795
}

go-audit-logs-example/.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories (remove the comment below to include it)
15+
# vendor/
16+
17+
# Environment Variables
18+
*.env

go-audit-logs-example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ An example Golang application demonstrating how to use the [WorkOS Golang SDK](h
3131

3232
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:
3333
- WORKOS_API_KEY=xxx
34-
-WORKOS_CLIENT_ID=xxx
34+
- WORKOS_CLIENT_ID=xxx
3535

3636
## Start the server
3737

go-audit-logs-example/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ require (
66
github.com/google/go-querystring v1.1.0 // indirect
77
github.com/gorilla/sessions v1.2.1
88
github.com/joho/godotenv v1.5.1
9-
github.com/workos/workos-go/v2 v2.1.0
9+
github.com/workos/workos-go/v3 v3.1.0
1010
)

go-audit-logs-example/go.sum

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@ github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyC
1010
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
1111
github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI=
1212
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
13-
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
14-
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
1513
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
1614
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
1715
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1816
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1917
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2018
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
2119
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
22-
github.com/workos/workos-go/v2 v2.0.2 h1:7CLsldo9Bqdyo+ikJO7bTnvVoD+U6GkqHoBfKHpQZZg=
23-
github.com/workos/workos-go/v2 v2.0.2/go.mod h1:5702ja1jMGArYgqS0lCowTNltHmYCJ8Uf4Iu2e+VNyw=
24-
github.com/workos/workos-go/v2 v2.1.0 h1:eZotGtDL1tw6Oq9CazlR+AMg//eBDX23bdfT616Pf8o=
25-
github.com/workos/workos-go/v2 v2.1.0/go.mod h1:5702ja1jMGArYgqS0lCowTNltHmYCJ8Uf4Iu2e+VNyw=
20+
github.com/workos/workos-go/v3 v3.1.0 h1:DHDQ5PWWsfie9ZjDw4xezVkNV5xEKAH21vMGQpc1DSo=
21+
github.com/workos/workos-go/v3 v3.1.0/go.mod h1:SUdYqICB2LG2G2UMMNI2EcBYX9OdpzgpNYlW6k0JML4=
2622
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
2723
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2824
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=

go-audit-logs-example/main.go

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,35 @@ import (
66
"log"
77
"net/http"
88
"os"
9+
"strconv"
910
"text/template"
1011
"time"
11-
"strconv"
1212

1313
"github.com/joho/godotenv"
1414

1515
"github.com/gorilla/sessions"
16-
"github.com/workos/workos-go/v2/pkg/auditlogs"
17-
"github.com/workos/workos-go/v2/pkg/organizations"
18-
"github.com/workos/workos-go/v2/pkg/portal"
19-
"github.com/workos/workos-go/v2/pkg/common"
20-
16+
"github.com/workos/workos-go/v3/pkg/auditlogs"
17+
"github.com/workos/workos-go/v3/pkg/common"
18+
"github.com/workos/workos-go/v3/pkg/organizations"
19+
"github.com/workos/workos-go/v3/pkg/portal"
2120
)
2221

2322
var router = http.NewServeMux()
2423
var key = []byte("super-secret-key")
2524
var store = sessions.NewCookieStore(key)
2625

27-
type SendEventData struct{
28-
Name string
29-
ID string
26+
type SendEventData struct {
27+
Name string
28+
ID string
3029
RangeStart string
31-
RangeEnd string
30+
RangeEnd string
3231
}
3332

3433
type Organizations struct {
35-
Data []organizations.Organization
34+
Data []organizations.Organization
3635
Metadata common.ListMetadata
37-
Before string
38-
After string
36+
Before string
37+
After string
3938
}
4039

4140
func init() {
@@ -45,8 +44,7 @@ func init() {
4544
}
4645
}
4746

48-
49-
// Displays Organizations
47+
// Displays Organizations
5048
func handleOrganizations(w http.ResponseWriter, r *http.Request) {
5149
tmpl := template.Must(template.ParseFiles("./static/index.html"))
5250

@@ -57,8 +55,8 @@ func handleOrganizations(w http.ResponseWriter, r *http.Request) {
5755
context.Background(),
5856
organizations.ListOrganizationsOpts{
5957
Before: before,
60-
After: after,
61-
Limit: 5,
58+
After: after,
59+
Limit: 5,
6260
},
6361
)
6462

@@ -74,7 +72,6 @@ func handleOrganizations(w http.ResponseWriter, r *http.Request) {
7472
return
7573
}
7674

77-
7875
data := Organizations{list.Data, list.ListMetadata, before, after}
7976

8077
// Render the template with the organizations
@@ -164,7 +161,7 @@ func sendEvents(w http.ResponseWriter, r *http.Request) {
164161
rangeStart := currentTime.AddDate(0, 0, -30)
165162

166163
data := SendEventData{session.Values["org_name"].(string), session.Values["org_id"].(string), rangeStart.Format(time.RFC3339), currentTime.Format(time.RFC3339)}
167-
164+
168165
if err := tmpl.Execute(w, data); err != nil {
169166
log.Panic(err)
170167
}
@@ -237,37 +234,37 @@ func sessionHandler(w http.ResponseWriter, r *http.Request) {
237234
}
238235
}
239236

240-
// Generates or exports CSV by form event
237+
// Generates or exports CSV by form event
241238
func exportEvents(w http.ResponseWriter, r *http.Request) {
242239
session, _ := store.Get(r, "session-name")
243-
eventType := r.FormValue("event")
240+
eventType := r.FormValue("event")
244241

245242
if eventType == "access_csv" {
246243
export, err := auditlogs.GetExport(context.Background(), auditlogs.GetExportOpts{
247244
ExportID: session.Values["export_id"].(string),
248245
})
249-
246+
250247
if err != nil {
251248
fmt.Println("Error exporting events:", err)
252249
}
253-
250+
254251
http.Redirect(w, r, export.URL, http.StatusSeeOther)
255252
} else {
256253
rangeStart := r.FormValue("range-start")
257254
rangeEnd := r.FormValue("range-end")
258255
targets := r.FormValue("filter-targets")
259-
opts := auditlogs.CreateExportOpts{
256+
opts := auditlogs.CreateExportOpts{
260257
OrganizationID: session.Values["org_id"].(string),
261258
RangeStart: rangeStart,
262259
RangeEnd: rangeEnd,
263-
Targets: []string{targets},
264-
}
260+
Targets: []string{targets},
261+
}
265262
if actors := r.FormValue("filter-actors"); actors != "" {
266-
opts.Actors = []string{actors}
263+
opts.Actors = []string{actors}
267264
}
268-
if actions:= r.FormValue("filter-actions"); actions != "" {
265+
if actions := r.FormValue("filter-actions"); actions != "" {
269266
opts.Actions = []string{actions}
270-
}
267+
}
271268

272269
export, err := auditlogs.CreateExport(context.Background(), opts)
273270

@@ -276,7 +273,6 @@ func exportEvents(w http.ResponseWriter, r *http.Request) {
276273
fmt.Println("Error creating export:", err)
277274
}
278275

279-
280276
session.Values["export_id"] = export.ID
281277

282278
if err := session.Save(r, w); err != nil {
@@ -288,10 +284,10 @@ func exportEvents(w http.ResponseWriter, r *http.Request) {
288284
}
289285

290286
// Generates an Admin Portal Link by Intent
291-
func events(w http.ResponseWriter, r *http.Request){
287+
func events(w http.ResponseWriter, r *http.Request) {
292288
intent := r.URL.Query().Get("intent")
293289
session, _ := store.Get(r, "session-name")
294-
290+
295291
link, err := portal.GenerateLink(
296292
context.Background(),
297293
portal.GenerateLinkOpts{
@@ -325,7 +321,6 @@ func main() {
325321
router.HandleFunc("/export-events", exportEvents)
326322
router.HandleFunc("/logout", logout)
327323

328-
329324
if err := http.ListenAndServe(":8000", router); err != nil {
330325
log.Panic(err)
331326
}

go-directory-sync-example/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
17+
# Environment Variables
18+
*.env

0 commit comments

Comments
 (0)