Skip to content

scalekit-inc/scalekit-sdk-go

Repository files navigation


Official Go SDK

Scalekit is an Enterprise Authentication Platform purpose built for B2B applications. This Go SDK helps implement Enterprise Capabilities like Single Sign-on via SAML or OIDC in your Golang applications within a few hours.


Pre-requisites

  1. Sign up for a Scalekit account.
  2. Get your env_url, client_id and client_secret from the Scalekit dashboard.

Installation

go get -u github.com/scalekit-inc/scalekit-sdk-go/v2

Usage

Initialize the Scalekit client using the appropriate credentials. Refer code sample below.

import "github.com/scalekit-inc/scalekit-sdk-go/v2"

func main() {
  scalekitClient := scalekit.NewScalekitClient(
    "<SCALEKIT_ENV_URL>",
    "<SCALEKIT_CLIENT_ID>",
    "<SCALEKIT_CLIENT_SECRET>",
  )

  // Use the sc object to interact with the Scalekit API
  authUrl, _ := scalekitClient.GetAuthorizationUrl(
    "https://acme-corp.com/redirect-uri",
    scalekit.AuthorizationUrlOptions{
      State: "state",
      ConnectionId: "con_123456789",
    },
  )
}
Minimum Requirements

Before integrating the Scalekit Go SDK, ensure your development environment meets these requirements:

Component Version
Go 1.22+

Note: Go 1.22+ provides the essential features required by this SDK. For optimal performance and security, consider using the latest stable release.

Examples - SSO with Go HTTP Server

Below is a simple code sample that showcases how to implement Single Sign-on using Scalekit SDK

package main

import (
  "fmt"
  "net/http"

  "github.com/scalekit-inc/scalekit-sdk-go/v2"
)

func main() {
  sc := scalekit.NewScalekit(
    "<SCALEKIT_ENV_URL>",
    "<SCALEKIT_CLIENT_ID>",
    "<SCALEKIT_CLIENT_SECRET>",
  )

  redirectUri := "http://localhost:8080/auth/callback"

  // Get the authorization URL and redirect the user to the IdP login page
  http.HandleFunc("/auth/login", func(w http.ResponseWriter, r *http.Request) {
    authUrl, _ := scalekitClient.GetAuthorizationUrl(
      redirectUri,
      scalekit.AuthorizationUrlOptions{
        State: "state",
        ConnectionId: "con_123456789",
      },
    )
    http.Redirect(w, r, authUrl, http.StatusSeeOther)
  })

  // Handle the callback from the Scalekit
  http.HandleFunc("/auth/callback", func(w http.ResponseWriter, r *http.Request) {
    code := r.URL.Query().Get("code")
    state := r.URL.Query().Get("state")

    authResp, _ := scalekitClient.AuthenticateWithCode(code, redirectUri)

    http.SetCookie(w, &http.Cookie{
      Name: "access_token",
      Value: authResp.AccessToken,
    })

    fmt.Fprintf(w, "Access token: %s", authResp.AccessToken)
  })

  fmt.Println("Server started at http://localhost:8080")
  http.ListenAndServe(":8080", nil)
}

Example Apps

Fully functional sample applications written using some popular web application frameworks and Scalekit SDK. Feel free to clone the repo and run them locally

API Reference

Refer to our API reference docs for detailed information about all our API endpoints and their usage.

More Information

License

This project is licensed under the MIT license. See the LICENSE file for more information.

About

Go SDK that empowers your app to implement Single Sign-On (SSO) for enterprises.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 8

Languages