Go logo

Integrate WorkOS using the Go SDK

Easily add enterprise features like Single Sign-On (SSO/SAML), Directory Sync (SCIM), Audit Trail (SIEM), and Access Control (IAM) to your Go app.

Installation

You can install the Go SDK using the following command:

Terminal

go get -u github.com/workos-inc/workos-go

Usage

Below is an example integration that adds SSO using the Go SDK. You can find other examples and more information in our Go SDK Docs.

Go

package main

import "github.com/workos-inc/workos-go/sso"

func main() {
  sso.Configure(
    "WORKOS_API_SECRET_KEY",
    "PROJECT_ID",
    "REDIRECT_URI",
  )
}

http.HandleFunc("/callback", func(w http.ResponseWriter, r *http.Request) {
  profile, err := sso.GetProfile(context.Background(), sso.GetProfileOptions{
    Code: r.URL.Query().Get("code"),
  })
  if err != nil {
    log.Printf("GetProfile failed: %s", err)
    w.WriteHeader(http.StatusInternalServerError)
    w.Write([]byte(err.Error()))
    return
  }

  user, err := FindUser(profile.email)
  if err != nil {
    log.Printf("Unable to find user: %s", err)
  }

  // SignIn(user) (your sign in implementation)
})

Start Integrating Today

Create an account to begin adding enterprise-ready features to your application today.