Skip to content

Commit

Permalink
Go update sdk versions (#34)
Browse files Browse the repository at this point in the history
* updated SDK to v3 in example apps

* removing files that should not have been added

* adding .gitignore files to each example application
  • Loading branch information
rarevalo13 authored Dec 28, 2023
1 parent 356fd9c commit 785571b
Show file tree
Hide file tree
Showing 24 changed files with 212 additions and 194 deletions.
18 changes: 18 additions & 0 deletions go-admin-portal-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Environment Variables
*.env
2 changes: 1 addition & 1 deletion go-admin-portal-example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ go 1.16
require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/joho/godotenv v1.5.1
github.com/workos/workos-go/v2 v2.1.0
github.com/workos/workos-go/v3 v3.1.0
)
8 changes: 2 additions & 6 deletions go-admin-portal-example/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@ github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/workos/workos-go/v2 v2.0.2 h1:7CLsldo9Bqdyo+ikJO7bTnvVoD+U6GkqHoBfKHpQZZg=
github.com/workos/workos-go/v2 v2.0.2/go.mod h1:5702ja1jMGArYgqS0lCowTNltHmYCJ8Uf4Iu2e+VNyw=
github.com/workos/workos-go/v2 v2.1.0 h1:eZotGtDL1tw6Oq9CazlR+AMg//eBDX23bdfT616Pf8o=
github.com/workos/workos-go/v2 v2.1.0/go.mod h1:5702ja1jMGArYgqS0lCowTNltHmYCJ8Uf4Iu2e+VNyw=
github.com/workos/workos-go/v3 v3.1.0 h1:DHDQ5PWWsfie9ZjDw4xezVkNV5xEKAH21vMGQpc1DSo=
github.com/workos/workos-go/v3 v3.1.0/go.mod h1:SUdYqICB2LG2G2UMMNI2EcBYX9OdpzgpNYlW6k0JML4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
Expand Down
12 changes: 5 additions & 7 deletions go-admin-portal-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"text/template"

"github.com/joho/godotenv"
"github.com/workos/workos-go/v2/pkg/organizations"
"github.com/workos/workos-go/v2/pkg/portal"
"github.com/workos/workos-go/v3/pkg/organizations"
"github.com/workos/workos-go/v3/pkg/portal"
)

func ProvisionEnterprise(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -39,7 +39,7 @@ func ProvisionEnterprise(w http.ResponseWriter, r *http.Request) {
func HandlePortal(w http.ResponseWriter, r *http.Request) {
organizationId := r.URL.Query().Get("id")
intent := r.URL.Query().Get("intent")

var linkIntent portal.GenerateLinkIntent
switch intent {
case "SSO":
Expand All @@ -55,18 +55,17 @@ func HandlePortal(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Invalid intent", http.StatusBadRequest)
return
}

link, err := portal.GenerateLink(context.Background(), portal.GenerateLinkOpts{
Organization: organizationId,
Intent: linkIntent,
Intent: linkIntent,
})
if err != nil {
log.Printf("get redirect failed: %s", err)
}
http.Redirect(w, r, link, http.StatusFound)
}


func main() {
err := godotenv.Load()
if err != nil {
Expand All @@ -91,7 +90,6 @@ func main() {
http.HandleFunc("/provision-enterprise", ProvisionEnterprise)
http.HandleFunc("/admin-portal", HandlePortal)


if err := http.ListenAndServe(conf.Addr, nil); err != nil {
log.Panic(err)
}
Expand Down
18 changes: 18 additions & 0 deletions go-audit-logs-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Environment Variables
*.env
2 changes: 1 addition & 1 deletion go-audit-logs-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ An example Golang application demonstrating how to use the [WorkOS Golang SDK](h

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:
- WORKOS_API_KEY=xxx
-WORKOS_CLIENT_ID=xxx
- WORKOS_CLIENT_ID=xxx

## Start the server

Expand Down
2 changes: 1 addition & 1 deletion go-audit-logs-example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/gorilla/sessions v1.2.1
github.com/joho/godotenv v1.5.1
github.com/workos/workos-go/v2 v2.1.0
github.com/workos/workos-go/v3 v3.1.0
)
8 changes: 2 additions & 6 deletions go-audit-logs-example/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@ github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyC
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI=
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/workos/workos-go/v2 v2.0.2 h1:7CLsldo9Bqdyo+ikJO7bTnvVoD+U6GkqHoBfKHpQZZg=
github.com/workos/workos-go/v2 v2.0.2/go.mod h1:5702ja1jMGArYgqS0lCowTNltHmYCJ8Uf4Iu2e+VNyw=
github.com/workos/workos-go/v2 v2.1.0 h1:eZotGtDL1tw6Oq9CazlR+AMg//eBDX23bdfT616Pf8o=
github.com/workos/workos-go/v2 v2.1.0/go.mod h1:5702ja1jMGArYgqS0lCowTNltHmYCJ8Uf4Iu2e+VNyw=
github.com/workos/workos-go/v3 v3.1.0 h1:DHDQ5PWWsfie9ZjDw4xezVkNV5xEKAH21vMGQpc1DSo=
github.com/workos/workos-go/v3 v3.1.0/go.mod h1:SUdYqICB2LG2G2UMMNI2EcBYX9OdpzgpNYlW6k0JML4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
Expand Down
61 changes: 28 additions & 33 deletions go-audit-logs-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,35 @@ import (
"log"
"net/http"
"os"
"strconv"
"text/template"
"time"
"strconv"

"github.com/joho/godotenv"

"github.com/gorilla/sessions"
"github.com/workos/workos-go/v2/pkg/auditlogs"
"github.com/workos/workos-go/v2/pkg/organizations"
"github.com/workos/workos-go/v2/pkg/portal"
"github.com/workos/workos-go/v2/pkg/common"

"github.com/workos/workos-go/v3/pkg/auditlogs"
"github.com/workos/workos-go/v3/pkg/common"
"github.com/workos/workos-go/v3/pkg/organizations"
"github.com/workos/workos-go/v3/pkg/portal"
)

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

type SendEventData struct{
Name string
ID string
type SendEventData struct {
Name string
ID string
RangeStart string
RangeEnd string
RangeEnd string
}

type Organizations struct {
Data []organizations.Organization
Data []organizations.Organization
Metadata common.ListMetadata
Before string
After string
Before string
After string
}

func init() {
Expand All @@ -45,8 +44,7 @@ func init() {
}
}


// Displays Organizations
// Displays Organizations
func handleOrganizations(w http.ResponseWriter, r *http.Request) {
tmpl := template.Must(template.ParseFiles("./static/index.html"))

Expand All @@ -57,8 +55,8 @@ func handleOrganizations(w http.ResponseWriter, r *http.Request) {
context.Background(),
organizations.ListOrganizationsOpts{
Before: before,
After: after,
Limit: 5,
After: after,
Limit: 5,
},
)

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


data := Organizations{list.Data, list.ListMetadata, before, after}

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

data := SendEventData{session.Values["org_name"].(string), session.Values["org_id"].(string), rangeStart.Format(time.RFC3339), currentTime.Format(time.RFC3339)}

if err := tmpl.Execute(w, data); err != nil {
log.Panic(err)
}
Expand Down Expand Up @@ -237,37 +234,37 @@ func sessionHandler(w http.ResponseWriter, r *http.Request) {
}
}

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

if eventType == "access_csv" {
export, err := auditlogs.GetExport(context.Background(), auditlogs.GetExportOpts{
ExportID: session.Values["export_id"].(string),
})

if err != nil {
fmt.Println("Error exporting events:", err)
}

http.Redirect(w, r, export.URL, http.StatusSeeOther)
} else {
rangeStart := r.FormValue("range-start")
rangeEnd := r.FormValue("range-end")
targets := r.FormValue("filter-targets")
opts := auditlogs.CreateExportOpts{
opts := auditlogs.CreateExportOpts{
OrganizationID: session.Values["org_id"].(string),
RangeStart: rangeStart,
RangeEnd: rangeEnd,
Targets: []string{targets},
}
Targets: []string{targets},
}
if actors := r.FormValue("filter-actors"); actors != "" {
opts.Actors = []string{actors}
opts.Actors = []string{actors}
}
if actions:= r.FormValue("filter-actions"); actions != "" {
if actions := r.FormValue("filter-actions"); actions != "" {
opts.Actions = []string{actions}
}
}

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

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


session.Values["export_id"] = export.ID

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

// Generates an Admin Portal Link by Intent
func events(w http.ResponseWriter, r *http.Request){
func events(w http.ResponseWriter, r *http.Request) {
intent := r.URL.Query().Get("intent")
session, _ := store.Get(r, "session-name")

link, err := portal.GenerateLink(
context.Background(),
portal.GenerateLinkOpts{
Expand Down Expand Up @@ -325,7 +321,6 @@ func main() {
router.HandleFunc("/export-events", exportEvents)
router.HandleFunc("/logout", logout)


if err := http.ListenAndServe(":8000", router); err != nil {
log.Panic(err)
}
Expand Down
3 changes: 3 additions & 0 deletions go-directory-sync-example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

# Dependency directories (remove the comment below to include it)
# vendor/

# Environment Variables
*.env
2 changes: 1 addition & 1 deletion go-directory-sync-example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ go 1.16
require (
github.com/gorilla/websocket v1.5.0
github.com/joho/godotenv v1.5.1
github.com/workos/workos-go/v2 v2.1.0
github.com/workos/workos-go/v3 v3.1.0
)
9 changes: 3 additions & 6 deletions go-directory-sync-example/go.sum
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/workos/workos-go/v2 v2.0.2 h1:7CLsldo9Bqdyo+ikJO7bTnvVoD+U6GkqHoBfKHpQZZg=
github.com/workos/workos-go/v2 v2.0.2/go.mod h1:5702ja1jMGArYgqS0lCowTNltHmYCJ8Uf4Iu2e+VNyw=
github.com/workos/workos-go/v2 v2.1.0 h1:eZotGtDL1tw6Oq9CazlR+AMg//eBDX23bdfT616Pf8o=
github.com/workos/workos-go/v2 v2.1.0/go.mod h1:5702ja1jMGArYgqS0lCowTNltHmYCJ8Uf4Iu2e+VNyw=
github.com/workos/workos-go/v3 v3.1.0 h1:DHDQ5PWWsfie9ZjDw4xezVkNV5xEKAH21vMGQpc1DSo=
github.com/workos/workos-go/v3 v3.1.0/go.mod h1:SUdYqICB2LG2G2UMMNI2EcBYX9OdpzgpNYlW6k0JML4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading

0 comments on commit 785571b

Please sign in to comment.