samlprovider

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 18 Imported by: 0

README

GoModularAuth SAML Provider Plugin (gomodularauth-saml-provider)

Go Reference

The SAML Provider Plugin enables GoModularAuth to act as a SAML 2.0 Identity Provider (IdP) for federating enterprise Single Sign-On (SSO).

Installation

go get github.com/BladiCreator/go-modular-auth/plugins/saml-provider

Quick Start

package main

import (
	"context"

	auth "github.com/BladiCreator/go-modular-auth"
	adaptermem "github.com/BladiCreator/go-modular-auth/adapters/memory"
	samlprovider "github.com/BladiCreator/go-modular-auth/plugins/saml-provider"
	"github.com/BladiCreator/go-modular-auth/user"
)

func main() {
	ctx := context.Background()

	engine, _ := auth.New(auth.Config{
		Adapter: adaptermem.NewAdapter(),
		Plugins: []auth.PluginModule{
			samlprovider.New(
				samlprovider.WithEntityID("https://auth.example.com/saml/idp"),
			),
		},
	})

	idp, _ := auth.Get[samlprovider.SAMLProvider](engine)

	// Register a trusted Service Provider
	_ = idp.RegisterSP(&samlprovider.ServiceProvider{
		EntityID: "https://sp.example.com",
		ACSURL:   "https://sp.example.com/saml/acs",
	})

	// Build signed SAML Response for an authenticated user
	u := &user.User{ID: "usr_alice", Email: "alice@example.com"}
	respBase64, _ := idp.BuildResponse(ctx, "https://sp.example.com", u, "_req_id")
	_ = respBase64
}

Detailed guide: doc/plugins/saml-provider.md.

Documentation

Overview

Package samlprovider provides SAML 2.0 Identity Provider capabilities (reserved module).

Index

Constants

View Source
const PluginID = "saml_provider"

Variables

View Source
var (
	ErrSPNotFound       = errors.New("samlprovider: service provider not found")
	ErrInvalidSP        = errors.New("samlprovider: invalid service provider")
	ErrInvalidUser      = errors.New("samlprovider: user is required")
	ErrKeyNotConfigured = errors.New("samlprovider: private key or certificate not configured")
)

Functions

func BuildSAMLResponseXML

func BuildSAMLResponseXML(idpEntityID string, sp *ServiceProvider, u *user.User, inResponseTo string, now time.Time, key *rsa.PrivateKey, certBase64 string) (string, error)

BuildSAMLResponseXML creates a valid SAML 2.0 Response XML document containing an authentication assertion.

Types

type Config

type Config struct {
	EntityID    string
	SSOURL      string
	PrivateKey  *rsa.PrivateKey
	Certificate string // base64 DER
}

type Module

type Module struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Module

func (*Module) ID

func (m *Module) ID() string

func (*Module) Init

func (m *Module) Init(h *auth.Host) error

type Option

type Option func(*Config)

func WithEntityID

func WithEntityID(entityID string) Option

func WithSSOURL

func WithSSOURL(ssoURL string) Option

func WithSigningKey

func WithSigningKey(pk *rsa.PrivateKey, certBase64 string) Option

type SAMLProvider

type SAMLProvider interface {
	GetMetadata() ([]byte, error)
	RegisterSP(sp *ServiceProvider) error
	GetSP(entityID string) (*ServiceProvider, error)
	BuildResponse(ctx context.Context, spEntityID string, u *user.User, inResponseTo string) (string, error)
}

type ServiceProvider

type ServiceProvider struct {
	EntityID    string `json:"entity_id"`
	ACSURL      string `json:"acs_url"`
	Certificate string `json:"certificate,omitempty"`
}

ServiceProvider represents an external SAML SP relying party.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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