nango

package
v0.1.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package nango is a credentials.Broker backed by Nango (https://nango.dev).

Nango runs the OAuth flow (Connect UI), stores and refreshes the tokens, and proxies API calls, so the agent only ever handles a connection ID. Only Nango's HTTP API is used, which works both against Nango Cloud and a self-hosted Nango (whose free tier includes Auth, Proxy and Connect UI). Docs:

Index

Constants

View Source
const DefaultBaseURL = "https://api.nango.dev"

DefaultBaseURL is Nango Cloud's API.

View Source
const EndUserTag = "end_user_id"

EndUserTag is the connection tag that ties a Nango connection to the agent's user.

View Source
const SignatureHeader = "X-Nango-Hmac-Sha256"

SignatureHeader carries the HMAC-SHA256 of a webhook body, keyed with the environment's webhook signing key (which is not the API secret key).

Variables

This section is empty.

Functions

This section is empty.

Types

type Broker

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

Broker implements credentials.Broker with Nango Connect and the Nango proxy. Connections are tagged with EndUserTag = the agent's user.

func NewBroker

func NewBroker(client *Client, cfg BrokerConfig) *Broker

NewBroker creates a broker on top of client.

func (*Broker) Await

Await implements credentials.Broker. It polls Nango for the user's connection, and checks at once when WebhookHandler reports one. Either way the grant comes from Lookup, never from the webhook body: a webhook only says when to look.

func (*Broker) Begin

func (b *Broker) Begin(ctx context.Context, user, integration string) (*credentials.Challenge, error)

Begin implements credentials.Broker by creating a Nango connect session.

func (*Broker) Lookup

func (b *Broker) Lookup(ctx context.Context, user, integration string) (credentials.Grant, error)

Lookup implements credentials.Broker. It returns the newest healthy connection the user has for the integration.

func (*Broker) WebhookHandler

func (b *Broker) WebhookHandler() http.Handler

WebhookHandler receives Nango's webhooks. A signed auth/creation webhook makes the matching Await check for the connection at once instead of at the next poll. Point the environment's webhook URL at it when Nango can reach this server. Without a signing key it answers 403 to everything.

type BrokerConfig

type BrokerConfig struct {
	// PollInterval is how often Await checks for the new connection. Default 2s.
	// Polling is what makes the flow work locally, where Nango can't reach a webhook.
	PollInterval time.Duration
	// WebhookSigningKey verifies webhooks (Nango environment settings, not the API key).
	// Without it WebhookHandler refuses every webhook and Await relies on polling.
	WebhookSigningKey string
	Logger            *slog.Logger
}

BrokerConfig configures a Broker.

type Client

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

Client calls Nango's HTTP API with a secret key.

func NewClient

func NewClient(secretKey, baseURL string, httpClient *http.Client) (*Client, error)

NewClient creates a client. baseURL defaults to DefaultBaseURL and httpClient to a client with a 30 second timeout.

func (*Client) CreateConnectSession

func (c *Client) CreateConnectSession(ctx context.Context, tags map[string]string, allowedIntegrations []string) (*ConnectSession, error)

CreateConnectSession creates a session that lets a user connect one of the allowed integrations. The tags are copied onto the connection the user creates.

func (*Client) ListConnections

func (c *Client) ListConnections(ctx context.Context, tags map[string]string) ([]Connection, error)

ListConnections lists the connections that carry all the given tags.

func (*Client) Proxy

func (c *Client) Proxy(ctx context.Context, method, integration, connectionID, path string, body io.Reader) (*http.Response, error)

Proxy sends a request to the provider's API through Nango, which adds the connection's credentials. path is the provider API path, for example "/calendar/v3/calendars/primary/events".

type ConnectSession

type ConnectSession struct {
	Token       string    `json:"token"`
	ConnectLink string    `json:"connect_link"`
	ExpiresAt   time.Time `json:"expires_at"`
}

ConnectSession is a short-lived session for Nango Connect (30 minutes).

type Connection

type Connection struct {
	ID                int               `json:"id"`
	ConnectionID      string            `json:"connection_id"`
	Provider          string            `json:"provider"`
	ProviderConfigKey string            `json:"provider_config_key"`
	Created           time.Time         `json:"created"`
	Tags              map[string]string `json:"tags"`
	Errors            []struct {
		Type  string `json:"type"`
		LogID string `json:"log_id"`
	} `json:"errors"`
}

Connection is a connection as listed by Nango (without credentials).

Jump to

Keyboard shortcuts

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