scalekit

package module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2024 License: MIT Imports: 24 Imported by: 0

README


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

Usage

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",
    },
  )
}

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"
)

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthenticationOptions

type AuthenticationOptions struct {
	CodeVerifier string
}

type AuthenticationResponse

type AuthenticationResponse struct {
	User        User
	IdToken     string
	AccessToken string
	ExpiresIn   int
}

type AuthorizationUrlOptions

type AuthorizationUrlOptions struct {
	ConnectionId        string
	OrganizationId      string
	Scopes              []string
	State               string
	Nonce               string
	DomainHint          string
	LoginHint           string
	CodeChallenge       string
	CodeChallengeMethod string
	Provider            string
}

type Connection

type Connection interface {
	GetConnection(ctx context.Context, organizationId string, id string) (*GetConnectionResponse, error)
	ListConnectionsByDomain(ctx context.Context, domain string) (*ListConnectionsResponse, error)
	ListConnections(ctx context.Context, organizationId string) (*ListConnectionsResponse, error)
	EnableConnection(ctx context.Context, organizationId string, id string) (*ToggleConnectionResponse, error)
	DisableConnection(ctx context.Context, organizationId string, id string) (*ToggleConnectionResponse, error)
}

type CreateDomainResponse

type CreateDomainResponse = domainsv1.CreateDomainResponse

type CreateOrganizationOptions

type CreateOrganizationOptions struct {
	ExternalId string
}

type Directory added in v1.0.3

type Directory interface {
	ListDirectories(ctx context.Context, organizationId string) (*ListDirectoriesResponse, error)
	ListDirectoryUsers(ctx context.Context, organizationId string, directoryId string, options *ListDirectoryUsersOptions) (*ListDirectoryUsersResponse, error)
	ListDirectoryGroups(ctx context.Context, organizationId string, directoryId string, options *ListDirectoryGroupsOptions) (*ListDirectoryGroupsResponse, error)
	GetPrimaryDirectoryByOrganizationId(ctx context.Context, organizationId string) (*GetDirectoryResponse, error)
	EnableDirectory(ctx context.Context, organizationId string, directoryId string) (*ToggleDirectoryResponse, error)
	DisableDirectory(ctx context.Context, organizationId string, directoryId string) (*ToggleDirectoryResponse, error)
	GetDirectory(ctx context.Context, organizationId string, directoryId string) (*GetDirectoryResponse, error)
}

type Domain

type Domain interface {
	CreateDomain(ctx context.Context, organizationId, name string) (*CreateDomainResponse, error)
	GetDomain(ctx context.Context, id string, organizationId string) (*GetDomainResponse, error)
	ListDomains(ctx context.Context, organizationId string) (*ListDomainResponse, error)
}

type Feature added in v1.0.3

type Feature struct {
	Name    string
	Enabled bool
}

type GetConnectionResponse

type GetConnectionResponse = connectionsv1.GetConnectionResponse

type GetDirectoryResponse added in v1.0.3

type GetDirectoryResponse = directoriesv1.GetDirectoryResponse

type GetDomainResponse

type GetDomainResponse = domainsv1.GetDomainResponse

type GrantType

type GrantType = string
const (
	GrantTypeAuthorizationCode GrantType = "authorization_code"
	GrantTypeRefreshToken      GrantType = "refresh_token"
	GrantTypeClientCredentials GrantType = "client_credentials"
)

type IdTokenClaims

type IdTokenClaims struct {
	Id                  string     `json:"sub"`
	Username            string     `json:"preferred_username"`
	Name                string     `json:"name"`
	GivenName           string     `json:"given_name"`
	FamilyName          string     `json:"family_name"`
	Email               string     `json:"email"`
	EmailVerified       bool       `json:"email_verified"`
	PhoneNumber         string     `json:"phone_number"`
	PhoneNumberVerified bool       `json:"phone_number_verified"`
	Profile             string     `json:"profile"`
	Picture             string     `json:"picture"`
	Gender              string     `json:"gender"`
	BirthDate           string     `json:"birthdate"`
	ZoneInfo            string     `json:"zoneinfo"`
	Locale              string     `json:"locale"`
	UpdatedAt           string     `json:"updated_at"`
	Identities          []Identity `json:"identities"`
	Metadata            string     `json:"metadata"`
}

type Identity

type Identity struct {
	ConnectionId          string `json:"connection_id"`
	OrganizationId        string `json:"organization_id"`
	ConnectionType        string `json:"connection_type"`
	ProviderName          string `json:"provider_name"`
	Social                bool   `json:"social"`
	ProviderRawAttributes string `json:"provider_raw_attributes"`
}

type IdpInitiatedLoginClaims added in v1.0.2

type IdpInitiatedLoginClaims struct {
	ConnectionID   string  `json:"connection_id"`
	OrganizationID string  `json:"organization_id"`
	LoginHint      string  `json:"login_hint"`
	RelayState     *string `json:"relay_state"`
}
type Link = organizationsv1.Link

type ListConnectionsResponse

type ListConnectionsResponse = connectionsv1.ListConnectionsResponse

type ListDirectoriesResponse added in v1.0.3

type ListDirectoriesResponse = directoriesv1.ListDirectoriesResponse

type ListDirectoryGroupsOptions added in v1.0.3

type ListDirectoryGroupsOptions struct {
	PageSize      uint32
	PageToken     string
	IncludeDetail *bool
	UpdatedAfter  *time.Time
}

type ListDirectoryGroupsResponse added in v1.0.3

type ListDirectoryGroupsResponse = directoriesv1.ListDirectoryGroupsResponse

type ListDirectoryUsersOptions added in v1.0.3

type ListDirectoryUsersOptions struct {
	PageSize         uint32
	PageToken        string
	IncludeDetail    *bool
	DirectoryGroupId *string
	UpdatedAfter     *time.Time
}

type ListDirectoryUsersResponse added in v1.0.3

type ListDirectoryUsersResponse = directoriesv1.ListDirectoryUsersResponse

type ListDomainResponse

type ListDomainResponse = domainsv1.ListDomainResponse

type ListOrganizationOptions added in v1.0.1

type ListOrganizationOptions = organizationsv1.ListOrganizationsRequest

type Organization

type Organization interface {
	CreateOrganization(ctx context.Context, name string, options CreateOrganizationOptions) (*CreateOrganizationResponse, error)
	ListOrganization(ctx context.Context, options *ListOrganizationOptions) (*ListOrganizationsResponse, error)
	GetOrganization(ctx context.Context, id string) (*GetOrganizationResponse, error)
	GetOrganizationByExternalId(ctx context.Context, externalId string) (*GetOrganizationResponse, error)
	UpdateOrganization(ctx context.Context, id string, organization *UpdateOrganization) (*UpdateOrganizationResponse, error)
	UpdateOrganizationByExternalId(ctx context.Context, externalId string, organization *UpdateOrganization) (*UpdateOrganizationResponse, error)
	DeleteOrganization(ctx context.Context, id string) error
	GeneratePortalLink(ctx context.Context, organizationId string) (*Link, error)
	GetPortalLinks(ctx context.Context, organizationId string) ([]*Link, error)
	DeletePortalLink(ctx context.Context, organizationId string, linkId string) error
	UpdateOrganizationSettings(ctx context.Context, id string, settings OrganizationSettings) (*GetOrganizationResponse, error)
}

type OrganizationSettings added in v1.0.3

type OrganizationSettings struct {
	Features []Feature
}

type Scalekit

type Scalekit interface {
	Connection() Connection
	Directory() Directory
	Domain() Domain
	Organization() Organization
	GetAuthorizationUrl(redirectUri string, options AuthorizationUrlOptions) (*url.URL, error)
	AuthenticateWithCode(
		code string,
		redirectUri string,
		options AuthenticationOptions,
	) (*AuthenticationResponse, error)
	GetIdpInitiatedLoginClaims(idpInitiateLoginToken string) (*IdpInitiatedLoginClaims, error)
	ValidateAccessToken(accessToken string) (bool, error)
	VerifyWebhookPayload(secret string, headers map[string]string, payload []byte) (bool, error)
}

func NewScalekitClient

func NewScalekitClient(envUrl, clientId, clientSecret string) Scalekit

type ToggleConnectionResponse

type ToggleConnectionResponse = connectionsv1.ToggleConnectionResponse

type ToggleDirectoryResponse added in v1.0.3

type ToggleDirectoryResponse = directoriesv1.ToggleDirectoryResponse

type UpdateOrganization

type UpdateOrganization = organizationsv1.UpdateOrganization

type User

type User = IdTokenClaims

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL