Categorygithub.com/overmindtech/connect
modulepackage
0.11.4
Repository: https://github.com/overmindtech/connect.git
Documentation: pkg.go.dev

# README

Connect

connect manages the NATS connections used by Overmind infrastructure to the NATS network. This includes:

  • Connecting
  • Reconnects
  • Error handing
  • Auth

Auth

In order to connect to NATS, a user needs an Nkey and a JWT. This JWT is issued by the Overmind API based on the permissions that the user calling the API has in the OAuth token they supply when calling it. This OAuth token comes from one of the following flows:

Client Credentials Flow

If the thing that is connecting already has the required permissions, then you can use the client credentials flow to get a token. If the application whose Client ID you supply is linked to a specific Organization then you can let the API connect you automatically:

flowConfig := ClientCredentialsConfig{
    ClientID:     "SOMETHING",
    ClientSecret: "SECRET",
}

client := NewOAuthTokenClient(
    fmt.Sprintf("https://%v/oauth/token", domain),
    exchangeURL,
    flowConfig,
)

o := NATSOptions{
    Servers:     []string{"nats://something"},
    TokenClient: client,
    NumRetries:  3,
    RetryDelay:  100 * time.Millisecond,
}

conn, err := o.Connect()

If however you need to connect to a specific Org, then you'll need an application with admin:write permissions, and to supply the org you want to connect to:

flowConfig := ClientCredentialsConfig{
    ClientID:     "SOMETHING",
    ClientSecret: "SECRET",
    Org:          "org_somethingHere",
}

client := NewOAuthTokenClient(
    fmt.Sprintf("https://%v/oauth/token", domain),
    exchangeURL,
    flowConfig,
)

o := NATSOptions{
    Servers:     []string{"nats://something"},
    TokenClient: client,
    NumRetries:  3,
    RetryDelay:  100 * time.Millisecond,
}

conn, err := o.Connect()

# Functions

NewBasicTokenClient Creates a new basic token client that simply returns a static token.
NewOAuthTokenClient Generates a token client that authenticates to OAuth using the client credentials flow, then uses that auth to get a NATS token.

# Constants

No description provided by the author
Defaults.
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

BasicTokenClient stores a static token and returns it when called, ignoring any provided NKeys or context since it already has the token and doesn't need to make any requests.
ClientCredentialsConfig Authenticates to Overmind using the Client Credentials flow https://auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow.
No description provided by the author
No description provided by the author
OAuthTokenClient Gets a NATS token by first authenticating to OAuth using the Client Credentials Flow, then using that token to retrieve a NATS token.

# Interfaces

TokenClient Represents something that is capable of getting NATS JWT tokens for a given set of NKeys.