goth: github.com/jtolds/goth Index | Files | Directories

package goth

import "github.com/jtolds/goth"

Package goth provides a simple, clean, and idiomatic way to write authentication packages for Go web applications.

This package was inspired by https://github.com/intridea/omniauth.

See the examples folder for a working application that lets users authenticate through Twitter or Facebook.

Index

Package Files

client.go doc.go provider.go session.go user.go

Variables

var HTTPClient = func(ctx context.Context) (*http.Client, error) {
    return http.DefaultClient, nil
}

Provider implementations should use this method for making outbound HTTP requests.

func ClearProviders Uses

func ClearProviders()

ClearProviders will remove all providers currently in use. This is useful, mostly, for testing purposes.

func UseProviders Uses

func UseProviders(viders ...Provider)

UseProviders sets a list of available providers for use with Goth.

type Params Uses

type Params interface {
    Get(string) string
}

Params is used to pass data to sessions for authorization. An existing implementation, and the one most likely to be used, is `url.Values`.

type Provider Uses

type Provider interface {
    // When implementing a provider, these methods should not make outbound
    // requests.
    Name() string
    UnmarshalSession(string) (Session, error)
    Debug(bool)
    // Refresh token is provided by auth provider or not
    RefreshTokenAvailable() bool

    // These three methods are deprecated. See the appropriate *Ctx replacement.
    BeginAuth(state string) (Session, error)
    FetchUser(Session) (User, error)
    RefreshToken(refreshToken string) (*oauth2.Token, error)

    // These methods are now preferred.
    BeginAuthCtx(ctx context.Context, state string) (Session, error)
    FetchUserCtx(context.Context, Session) (User, error)
    // Get new access token based on the refresh token.
    // Only works if RefreshTokenAvailable() is true
    RefreshTokenCtx(ctx context.Context, refreshToken string) (*oauth2.Token, error)
}

Provider needs to be implemented for each 3rd party authentication provider e.g. Facebook, Twitter, etc...

func GetProvider Uses

func GetProvider(name string) (Provider, error)

GetProvider returns a previously created provider. If Goth has not been told to use the named provider it will return an error.

type Providers Uses

type Providers map[string]Provider

Providers is list of known/available providers.

func GetProviders Uses

func GetProviders() Providers

GetProviders returns a list of all the providers currently in use.

type Session Uses

type Session interface {
    // GetAuthURL returns the URL for the authentication end-point for the
    // provider. Implementations should not make outbound HTTP requests.
    GetAuthURL() (string, error)
    // Marshal generates a string representation of the Session for storing
    // between requests. Implementations should not make outbound HTTP requests.
    Marshal() string

    // This method is deprecated. Please see AuthorizeCtx.
    Authorize(Provider, Params) (string, error)

    // This method is now preferred.
    // Authorize should validate the data from the provider and return an access
    // token that can be stored for later access to the provider.
    AuthorizeCtx(context.Context, Provider, Params) (string, error)
}

Session needs to be implemented as part of the provider package. It will be marshaled and persisted between requests to "tie" the start and the end of the authorization process with a 3rd party provider.

type User Uses

type User struct {
    RawData           map[string]interface{}
    Provider          string
    Email             string
    Name              string
    FirstName         string
    LastName          string
    NickName          string
    Description       string
    UserID            string
    AvatarURL         string
    Location          string
    AccessToken       string
    AccessTokenSecret string
    RefreshToken      string
    ExpiresAt         time.Time
}

User contains the information common amongst most OAuth and OAuth2 providers. All of the "raw" datafrom the provider can be found in the `RawData` field.

Directories

PathSynopsis
examples
gothicPackage gothic wraps common behaviour when using Goth.
providers/amazonPackage amazon implements the OAuth2 protocol for authenticating users through amazon.
providers/bitbucketPackage bitbucket implements the OAuth2 protocol for authenticating users through Bitbucket.
providers/boxPackage box implements the OAuth2 protocol for authenticating users through box.
providers/cloudfoundryPackage cloudfoundry implements the OAuth2 protocol for authenticating users through Cloud Foundry This package can be used as a reference implementation of an OAuth2 provider for Goth.
providers/dailymotionPackage dailymotion implements the OAuth2 protocol for authenticating users through Dailymotion.
providers/deezerPackage deezer implements the OAuth2 protocol for authenticating users through Deezer.
providers/digitalocean
providers/discordPackage discord implements the OAuth2 protocol for authenticating users through Discord.
providers/dropboxPackage dropbox implements the OAuth2 protocol for authenticating users through Dropbox.
providers/facebookPackage facebook implements the OAuth2 protocol for authenticating users through Facebook.
providers/fauxPackage faux is used exclusively for testing purposes.
providers/fitbitPackage fitbit implements the OAuth protocol for authenticating users through Fitbit.
providers/githubPackage github implements the OAuth2 protocol for authenticating users through Github.
providers/gitlabPackage gitlab implements the OAuth2 protocol for authenticating users through gitlab.
providers/gplusPackage gplus implements the OAuth2 protocol for authenticating users through Google+.
providers/herokuPackage heroku implements the OAuth2 protocol for authenticating users through heroku.
providers/influxcloudPackage influxdata implements the OAuth2 protocol for authenticating users through InfluxCloud.
providers/instagram
providers/intercomPackage intercom implements the OAuth protocol for authenticating users through Intercom.
providers/lastfmPackage lastfm implements the OAuth protocol for authenticating users through LastFM.
providers/linkedinPackage linkedin implements the OAuth2 protocol for authenticating users through Linkedin.
providers/onedrivePackage onedrive implements the OAuth2 protocol for authenticating users through onedrive.
providers/paypalPackage paypal implements the OAuth2 protocol for authenticating users through paypal.
providers/salesforcePackage salesforce implements the OAuth2 protocol for authenticating users through salesforce.
providers/slackPackage slack implements the OAuth2 protocol for authenticating users through slack.
providers/soundcloudPackage soundcloud implements the OAuth2 protocol for authenticating users through soundcloud.
providers/spotifyPackage spotify implements the OAuth protocol for authenticating users through Spotify.
providers/steamPackage steam implements the OpenID protocol for authenticating users through Steam.
providers/stripePackage stripe implements the OAuth2 protocol for authenticating users through stripe.
providers/twitchPackage twitch implements the OAuth2 protocol for authenticating users through Twitch.
providers/twitterPackage twitter implements the OAuth protocol for authenticating users through Twitter.
providers/uberPackage uber implements the OAuth2 protocol for authenticating users through uber.
providers/wepayPackage wepay implements the OAuth2 protocol for authenticating users through wepay.
providers/yahooPackage yahoo implements the OAuth2 protocol for authenticating users through yahoo.
providers/yammerPackage yammer implements the OAuth2 protocol for authenticating users through yammer.

Package goth imports 6 packages (graph) and is imported by 38 packages. Updated 2019-08-07. Refresh now. Tools for package owners.