jambo

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: MIT Imports: 23 Imported by: 0

README

jambo

jambo is an Go package to build an OpenID Connect provider (OIDC server).

"Jambo" is also a Swahili word. It translates to "hello" or "hi". It's a common greeting used in East Africa, particularly in Tanzania and Kenya.

In order to create a OpenID Connect provider, you will have to create a new server, which is in turn a HTTP handler.

This is a complete example:

package main

import (
	"github.com/cespedes/jambo"
)

func main() {
	issuer := "https://example.com/oidc"
	root := "/oidc"
	s := jambo.NewServer(issuer, root)

	clientID := "test-client"
	clientSecret := "client-secret"
	s.AddClient(clientID, clientSecret)

	s.SetCallback(func (user, pass string) bool {
		if req.User == "admin" && req.Password == "secret" {
			return jambo.Response{Type: jambo.ResponseTypeLoginOK}
		}
		return jambo.Response{Type: jambo.ResponseTypeLoginFailed}
	})

	http.ListenAndServe(":8080", s)
}

It will create a HTTP server, listening to requests under root and providing all the necessary handlers for the OIDC provider.


The OpenID Connect specification is here:

  • https://openid.net/specs/openid-connect-discovery-1_0.html
  • https://openid.net/specs/openid-connect-core-1_0.html

Other OpenID Connect providers

2FA workflow

  • User goes to (client-end-point)
  • (client-end-point) redirects user to (issuer)/auth
  • In that page, it asks for user and password
  • jambo calls authenticate(user, password)
  • If password is incorrect, inform and try again
  • If password is correct and 2FA is not needed, authenticate and redirect to (client-callback)
  • If password is correct and 2FA is needed, show 2FA options and let the user choose 1
  • After choosing one, do some things (like sending an SMS) and ask for additional info (secret sent via SMS)
  • If secret is correct, authenticate and proceed to (client-callback)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ID           string
	Secret       string
	RedirectURIs []string
}

type Connection

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

type IDToken

type IDToken struct {
	Issuer            string   `json:"iss"`
	SubjectIdentifier string   `json:"sub"`
	Audience          string   `json:"aud"`
	Expiration        int64    `json:"exp"`
	IssuedAt          int64    `json:"iat"`
	Nonce             string   `json:"nonce,omitempty"`
	PreferredUsername string   `json:"preferred_username,omitempty"`
	Name              string   `json:"name,omitempty"`
	Email             string   `json:"email,omitempty"`
	EmailVerified     bool     `json:"email_verified,omitempty"`
	Groups            []string `json:"groups,omitempty"`
}

https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.2

type Request

type Request struct {
	Type     RequestType
	Client   string
	User     string
	Password string
	MFAType  string
	OTPValue string
}

type RequestType

type RequestType int
const (
	RequestTypeInvalid      RequestType = iota
	RequestTypeUserPassword             // regular authentication: user and password
	RequestTypeSendOTP                  // client is requesting OTP to be sent to their devices
	RequestTypeOTP                      // client has just sent the OTP to be checked
)

type Response

type Response struct {
	Type ResponseType // the following fields depend on this type:

	// If Type == ResponseTypeLoginOK:
	User   string // login for the user. Usually the same sent in the request.
	Name   string // user name and surname.
	Mail   string
	Groups []string
}

type ResponseType

type ResponseType int
const (
	ResponseTypeInvalid     ResponseType = iota
	ResponseTypeOK                       // No errors
	ResponseTypeLoginOK                  // login is successful
	ResponseTypeLoginFailed              // login failed
	ResponseType2FANeeded                // login is successful so far, but we need 2FA
)

type Server

type Server struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewServer

func NewServer(issuer, root string) *Server

func (*Server) AddClient

func (s *Server) AddClient(clientID, clientSecret string, redirectURIs []string)

AddClient adds a new client to the server. It cannot be used concurrently with any other access to Server.

func (*Server) AddStaticFS

func (s *Server) AddStaticFS(filesystem fs.FS)

func (*Server) GetClient

func (s *Server) GetClient(r *http.Request) *Client

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) SetCallback

func (s *Server) SetCallback(f func(req *Request) Response)

func (*Server) SetClient

func (s *Server) SetClient(r *http.Request, client *Client) *http.Request

Directories

Path Synopsis
cmd
oidc-server command
Package mergefs provides support for merging multiple filesystems together.
Package mergefs provides support for merging multiple filesystems together.

Jump to

Keyboard shortcuts

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