Enterprise SAML SSO in Go: Adding Okta, Azure AD, and Google Workspace Auth With SSOJet
The post Enterprise SAML SSO in Go: Adding Okta, Azure AD, and Google Workspace Auth With SSOJet appeared first on SSOJet – Enterprise SSO & Identity Solutions.
According to the JetBrains 2024 Developer Ecosystem Survey, Go usage in production continues to grow rapidly among backend engineering teams. Go is now one of the most common choices for modern APIs, SaaS platforms, infrastructure tooling, and cloud-native applications.
Yet enterprise SSO implementation in Go remains surprisingly fragmented.
Most Go SAML tutorials stop after configuring a single Okta tenant using crewjam/saml. The real problems begin when the second enterprise customer arrives and the application suddenly needs:
-
multi-tenant IdP routing
-
certificate rotation support
-
tenant-aware login discovery
-
metadata management
-
Azure AD compatibility
-
enterprise onboarding workflows
After helping 100+ B2B SaaS engineering teams ship enterprise authentication, the same pattern appears repeatedly: developers start by implementing SAML directly in Go, then gradually realize they are building an identity platform instead of an application.
This guide shows the modern Go architecture:
-
enterprise customers configure SAML in SSOJet
-
SSOJet brokers the SAML federation
-
your Go application integrates using OpenID Connect (OIDC)
Your Go service never parses SAML XML directly.
How the Architecture Works
Instead of your Go application acting as a SAML Service Provider directly, SSOJet sits between the enterprise IdP and your application.
Okta / Azure AD / Google Workspace
↓ SAML
SSOJet
↓ OIDC
Go Application
This architecture removes the hardest parts of enterprise SAML from your Go codebase:
-
no XML parsing
-
no assertion validation
-
no
xmlsec1 -
no ACS endpoint handling
-
no metadata parsing
-
no certificate rotation logic
-
no IdP-specific SAML quirks
Your Go application behaves like a standard OIDC client.
SSOJet handles the federation layer.
For a deeper breakdown of enterprise federation concepts, see the SSOJet SAML Glossary.
Why Go SSO Is Different From Other Ecosystems
Go intentionally keeps the standard library minimal.
Unlike Spring Boot, ASP.NET, or Django:
-
there is no built-in authentication framework
-
there is no default session abstraction
-
there is no standard enterprise auth middleware
-
there is no official RBAC system
That flexibility is one of Go's strengths, but it also means SSO architecture decisions matter much earlier.
Direct SAML implementations in Go quickly become operationally heavy because the application itself must manage:
-
tenant metadata
-
IdP certificates
-
XML validation
-
SAML assertions
-
ACS routing
-
session state
SSOJet removes that complexity by turning enterprise SAML into a standard OIDC login flow.
Why OIDC Is the Better Integration Layer for Go
OIDC integrates naturally with Go's HTTP ecosystem because it works over standard HTTPS requests and JSON payloads.
That means your Go application can use:
-
net/http -
chi -
gin -
echo -
gorilla/sessions -
Redis session stores
-
JWT middleware
without introducing XML tooling or SAML-specific infrastructure.
This is especially valuable in:
-
Kubernetes environments
-
serverless deployments
-
containerized microservices
-
edge/serverless Go runtimes
because you avoid native SAML dependencies entirely.
Build vs Broker: The Real Tradeoff
|
Dimension |
Direct SAML in Go |
SSOJet + OIDC |
|---|---|---|
|
XML parsing |
You maintain |
Managed by SSOJet |
|
Certificate rotation |
DIY |
Managed |
|
Multi-tenant routing |
DIY |
Built in |
|
Azure AD quirks |
Your problem |
Abstracted |
|
Metadata handling |
Manual |
Automated |
|
|
Required in many setups |
None |
|
Time to first enterprise login |
1 to 3 weeks |
4 to 6 hours |
|
Operational complexity |
High |
Low |
For a single internal customer, direct SAML can work.
For a multi-tenant B2B SaaS product, the broker model is significantly easier to maintain.
Prerequisites
You need:
-
Go 1.22+
-
An SSOJet account
-
At least one enterprise SAML connection configured
-
gorilla/sessions -
godotenv -
openid-connect-goor equivalent OIDC library
For local testing, use:
-
ngrok -
Cloudflare Tunnel
because most enterprise IdPs reject localhost callback URLs.
Configure Enterprise SAML in SSOJet
Before writing Go code, configure your enterprise connection in the SSOJet dashboard.
Inside SSOJet:
-
Create a new SAML connection
-
Choose the IdP:
-
Okta
-
Azure AD
-
Google Workspace
-
OneLogin
-
Ping Identity
-
-
Upload metadata XML or enter:
-
SSO URL
-
Entity ID
-
X.509 certificate
-
-
Configure allowed email domains
-
Save the connection
SSOJet now becomes the federation broker for that enterprise tenant.
Your Go application communicates only with SSOJet using OIDC.
You can review the official setup flow in the SSOJet Go SSO Documentation.
Create the Go Project
Initialize the Module
mkdir acme-go-sso && cd acme-go-sso
go mod init github.com/acme/acme-go-sso
Install Dependencies
go get github.com/coreos/go-oidc/v3/oidc
go get golang.org/x/oauth2
go get github.com/gorilla/sessions
go get github.com/joho/godotenv
Configure Environment Variables
Create .env:
SSOJET_ISSUER=https://your-project.auth.ssojet.com
SSOJET_CLIENT_ID=your_client_id
SSOJET_CLIENT_SECRET=your_client_secret
SSOJET_REDIRECT_URI=https://your-ngrok-url.ngrok.io/auth/callback
SESSION_SECRET=replace_with_secure_random_value
Create the Main HTTP Server
main.go
package main
import (
"context"
"log"
"net/http"
"os"
"github.com/coreos/go-oidc/v3/oidc"
"github.com/gorilla/sessions"
"github.com/joho/godotenv"
"golang.org/x/oauth2"
)
var (
store *sessions.CookieStore
oauth2Config oauth2.Config
oidcVerifier *oidc.IDTokenVerifier
)
func main() {
_ = godotenv.Load()
ctx := context.Background()
provider, err := oidc.NewProvider(
ctx,
os.Getenv("SSOJET_ISSUER"),
)
if err != nil {
log.Fatal(err)
}
oauth2Config = oauth2.Config{
ClientID: os.Getenv("SSOJET_CLIENT_ID"),
ClientSecret: os.Getenv("SSOJET_CLIENT_SECRET"),
RedirectURL: os.Getenv("SSOJET_REDIRECT_URI"),
Endpoint: provider.Endpoint(),
Scopes: []string{
"openid",
"profile",
"email",
},
}
oidcVerifier = provider.Verifier(&oidc.Config{
ClientID: os.Getenv("SSOJET_CLIENT_ID"),
})
store = sessions.NewCookieStore(
[]byte(os.Getenv("SESSION_SECRET")),
)
store.Options = &sessions.Options{
Path: "/",
MaxAge: 60 * 60 * 8,
HttpOnly: true,
Secure: true,
SameSite: http.SameSiteLaxMode,
}
mux := http.NewServeMux()
mux.HandleFunc("/login", loginHandler)
mux.HandleFunc("/auth/callback", callbackHandler)
mux.HandleFunc("/dashboard", requireAuth(dashboardHandler))
mux.HandleFunc("/logout", logoutHandler)
log.Println("Listening on :8080")
http.ListenAndServe(":8080", mux)
}
SameSiteLaxMode is important here.
OIDC authentication involves cross-site redirects, and using Strict often causes broken login loops because the browser refuses to send the session cookie during the redirect flow.
Create the Login Handler
Redirect Users to SSOJet
func loginHandler(w http.ResponseWriter, r *http.Request) {
email := r.URL.Query().Get("email")
state := generateState()
authCodeURL := oauth2Config.AuthCodeURL(
state,
oauth2.SetAuthURLParam("login_hint", email),
)
http.Redirect(w, r, authCodeURL, http.StatusTemporaryRedirect)
}
The optional login_hint parameter helps SSOJet identify which enterprise IdP connection should handle authentication.
Example:
-
[email protected]→ Okta -
[email protected]→ Azure AD
This enables true multi-tenant enterprise routing.
Learn more about domain-based discovery in the SSOJet SAML SSO Documentation.
Create the OIDC Callback Handler
Exchange Authorization Code
func callbackHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
code := r.URL.Query().Get("code")
oauth2Token, err := oauth2Config.Exchange(ctx, code)
if err != nil {
http.Error(w, "token exchange failed", http.StatusInternalServerError)
return
}
rawIDToken, ok := oauth2Token.Extra("id_token").(string)
if !ok {
http.Error(w, "missing id_token", http.StatusInternalServerError)
return
}
idToken, err := oidcVerifier.Verify(ctx, rawIDToken)
if err != nil {
http.Error(w, "invalid token", http.StatusUnauthorized)
return
}
var profile struct {
Sub string `json:"sub"`
Email string `json:"email"`
Name string `json:"name"`
}
if err := idToken.Claims(&profile); err != nil {
http.Error(w, "claims parse failed", http.StatusInternalServerError)
return
}
session, _ := store.Get(r, "ssojet_session")
session.Values["user_id"] = profile.Sub
session.Values["email"] = profile.Email
session.Values["name"] = profile.Name
if err := session.Save(r, w); err != nil {
http.Error(w, "session save failed", http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/dashboard", http.StatusSeeOther)
}
Notice what is missing:
-
no
SAMLResponse -
no XML parsing
-
no assertion validation
-
no ACS endpoint logic
SSOJet handles all SAML federation internally.
Your Go application only consumes OIDC identity data.
Protect Routes With Middleware
Session Middleware
func requireAuth(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session, _ := store.Get(r, "ssojet_session")
userID, ok := session.Values["user_id"].(string)
if !ok || userID == "" {
http.Redirect(w, r, "/login", http.StatusSeeOther)
return
}
next(w, r)
}
}
Create Dashboard and Logout Handlers
func dashboardHandler(w http.ResponseWriter, r *http.Request) {
session, _ := store.Get(r, "ssojet_session")
email := session.Values["email"]
w.Header().Set("Content-Type", "text/html")
w.Write([]byte(
"<h1>Welcome " + email.(string) + "</h1>",
))
}
func logoutHandler(w http.ResponseWriter, r *http.Request) {
session, _ := store.Get(r, "ssojet_session")
session.Options.MaxAge = -1
session.Save(r, w)
http.Redirect(w, r, "/", http.StatusSeeOther)
}
Testing Locally With ngrok
Most enterprise IdPs reject localhost callback URLs.
Use:
ngrok http 8080
Then update:
SSOJET_REDIRECT_URI=https://your-ngrok-url.ngrok.io/auth/callback
inside:
-
your Go application
-
your SSOJet application settings
You can also use the SSOJet SAML Tester to validate enterprise SSO flows during development.
Production Considerations
Use Server-Side Session Storage
gorilla/sessions cookie storage has practical size limitations.
Enterprise customers with hundreds of groups can overflow cookies.
For production:
-
Redis
-
PostgreSQL-backed sessions
-
Memcached
are better choices.
Configure Reverse Proxies Correctly
Behind:
-
NGINX
-
Caddy
-
Cloudflare
-
AWS ALB
ensure:
-
X-Forwarded-Proto -
X-Forwarded-Host
are forwarded correctly.
Otherwise callback URLs may incorrectly use http://.
That causes OIDC redirect URI mismatches.
Use Secure Session Cookies
Always configure:
Secure: true
HttpOnly: true
SameSite: http.SameSiteLaxMode
This is especially important for enterprise security reviews and compliance questionnaires.
Common Go Enterprise SSO Mistakes
Implementing Raw SAML Directly
Most teams underestimate SAML operational complexity.
OIDC federation is significantly easier to maintain long term.
Hardcoding a Single Okta Tenant
Your second enterprise customer immediately exposes the architectural limitations.
Always design for multi-tenant routing.
Storing Too Much Data in Cookies
Large group memberships often exceed browser cookie limits.
Prefer server-side sessions.
Forgetting Session Rotation
Regenerate sessions after login to reduce session fixation risk.
Compliance Considerations
Enterprise customers increasingly require:
-
SOC 2
-
ISO 27001
-
GDPR
-
audit logging
-
secure authentication infrastructure
SSOJet maintains:
-
SOC 2 Type II
-
ISO 27001
-
GDPR readiness
-
OpenID Certified infrastructure
You can also integrate with SSOJet Audit Logs for centralized authentication event visibility.
Frequently Asked Questions
Should I use crewjam/saml directly?
For a single internal SAML integration, possibly.
For a multi-tenant B2B SaaS platform, using SSOJet as the federation broker dramatically reduces operational complexity.
Can I use chi, gin, or echo instead of net/http?
Yes.
The OIDC flow works identically across:
-
chi
-
gin
-
echo
-
fiber
-
standard
net/http
Does this work on AWS Lambda?
Yes.
Because the Go application only handles HTTPS-based OIDC requests, there are no native SAML dependencies like xmlsec1.
That makes serverless deployment significantly simpler.
Can I support multiple Okta and Azure AD tenants?
Yes.
Each enterprise customer becomes a separate SSOJet connection.
Your Go code remains unchanged.
How do I test enterprise SSO locally?
Use:
-
ngrok
-
Cloudflare Tunnel
-
SSOJet SAML Tester
to validate callback flows locally.
Final Thoughts
The biggest mistake Go teams make with enterprise SSO is assuming they need to become SAML experts.
Most do not.
The cleaner architecture is:
-
enterprise SAML handled by SSOJet
-
Go application integrates using OIDC
-
your application focuses on business logic
-
SSOJet handles federation complexity
That reduces implementation time, onboarding friction, and long-term maintenance overhead significantly.
If you're building a B2B SaaS product in Go, this architecture is substantially easier to operate than maintaining direct SAML infrastructure inside your application.

