goath

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: MIT Imports: 8 Imported by: 0

README

goath

This package is an attempt to provide nice OAuth2 / OpenID Connect (OIDC) interface.

OAuth2 integration is provided in the "x" package. For OpenID Connect (OIDC) providers, please have a look at the other subpackages.

Documentation

Overview

package goath is an attempt to provide nice OAuth2 / OpenID Connect (OIDC) interface.

OAuth2 integration is provided in the "x" package. For OpenID Connect (OIDC) providers, please have a look at the other subpackages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthCodeURLWithPKCE added in v0.2.0

func AuthCodeURLWithPKCE(authCodeURL func(state string, opts ...oauth2.AuthCodeOption) string, state string) (url, pkceVerifier string, err error)

AuthCodeURLWithPKCE is a helper method to generate PKCE codes and send the challenge to the provider (and returning the verifier for later user).

func SetStateCookie added in v0.2.0

func SetStateCookie(w http.ResponseWriter, intendedURL, prefix string)

SetStateCookie is used to set the state cookie, which stores the intended URL of the user before authentication.

Types

type CallbackResult added in v0.2.0

type CallbackResult struct {
	// UnmarshalUser will unmarshal the JSON user returned by the provider
	//      var user struct {
	//      	ID    string `json:"sub"`
	//      	Email string `json:"email"`
	//      	Name  string `json:"name"`
	//      }
	//      err = UnmarshalUser(&user)
	UnmarshalUser func(interface{}) error
	Token         *oauth2.Token
	IntendedPath  string
}

type CookieEncrypter added in v0.2.0

type CookieEncrypter interface {
	Seal(name, cleartext string) string
	Open(name, cyphertext string) (string, error)
}

type ExchangeHandler added in v0.2.0

type ExchangeHandler struct {
	CookiePrefix    string
	CookieEncrypter CookieEncrypter
}

ExchangeHandler implements the exchange-code flow (including PKCE challenge).

func (ExchangeHandler) HandleCallback added in v0.2.0

func (s ExchangeHandler) HandleCallback(w http.ResponseWriter, r *http.Request, provider Provider) (cr CallbackResult, clearCookies func(), err error)

HandleCallback should be called after the user logged in at the provider.

func (ExchangeHandler) RedirectToAuthCodeURL added in v0.2.0

func (s ExchangeHandler) RedirectToAuthCodeURL(w http.ResponseWriter, r *http.Request, provider Provider) error

RedirectToAuthCodeURL should be called to redirect the user to the provider for login.

type JWT added in v0.2.5

type JWT interface {
	AssertionType() string
	Assertion(aud string) (string, error)
}

type Provider

type Provider interface {
	// SetRedirectURL sets the local callback URL.
	SetRedirectURL(url string)

	// AuthCodeURL returns the Provider URL to redirect the user to.
	AuthCodeURL(state string) (url, pkceVerifier string, err error)

	// Exchange exchanges the code and provides a way to unmarshal the user info.
	//
	//      var user struct {
	//      	ID    string `json:"sub"`
	//      	Email string `json:"email"`
	//      	Name  string `json:"name"`
	//      }
	//      err = unmarshalUser(&user)
	Exchange(code, pkceVerifier string) (token *oauth2.Token, unmarshalUser func(interface{}) error, err error)
}

Provider is an interface suitable for OAuth2 and OIDC flows.

Directories

Path Synopsis
package coreos provides a Provider for OpenID Connect (oidc), backed by the github.com/coreos/go-oidc/v3/oidc package.
package coreos provides a Provider for OpenID Connect (oidc), backed by the github.com/coreos/go-oidc/v3/oidc package.
package goathtesting is used to test the different providers.
package goathtesting is used to test the different providers.
package refresh uses the refresh-token as a remember token (stored encrypted in a dedicated cookie).
package refresh uses the refresh-token as a remember token (stored encrypted in a dedicated cookie).
x
package x uses golang.org/x/oauth2 to implement a Provider for the OAuth2 flow.
package x uses golang.org/x/oauth2 to implement a Provider for the OAuth2 flow.
package zitadel provides a Provider for OpenID Connect (oidc), backed by the github.com/zitadel/oidc/pkg/client package.
package zitadel provides a Provider for OpenID Connect (oidc), backed by the github.com/zitadel/oidc/pkg/client package.

Jump to

Keyboard shortcuts

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