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.
- Sign up for a Scalekit account.
- Get your
env_url
,client_id
andclient_secret
from the Scalekit dashboard.
go get -u github.com/scalekit-inc/scalekit-sdk-go
Initialize the Scalekit client using the appropriate credentials. Refer code sample below.
import "github.com/scalekit-inc/scalekit-sdk-go"
func main() {
scalekitClient := scalekit.NewScalekit(
"<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",
},
)
}
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"
)
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)
}
Fully functional sample applications written using some popular web application frameworks and Scalekit SDK. Feel free to clone the repo and run them locally
Refer to our API reference docs for detailed information about all our API endpoints and their usage.
- Quickstart Guide to implement Single Sign-on in your application: SSO Quickstart Guide
- Understand Single Sign-on basics: SSO Basics
This project is licensed under the MIT license. See the LICENSE file for more information.