provider

package
v0.0.0-...-7b6f2c3 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: MIT Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UserToken = ""

Functions

This section is empty.

Types

type Auth0Provider

type Auth0Provider struct {
	Config        Config
	OAuth2        *oauth2.Config
	NewHTTPClient func() *http.Client
}

Auth0Provider configuration with new http client

func NewAuth0Provider

func NewAuth0Provider(config Config) *Auth0Provider

NewAuth0Provider creates OAuth client

func (*Auth0Provider) AuthCodeURL

func (p *Auth0Provider) AuthCodeURL(csrfToken string) string

AuthCodeURL returns URL for redirecting to the authentication web page

func (*Auth0Provider) Exchange

func (p *Auth0Provider) Exchange(ctx context.Context, authorizationProvider, authorizationCode string) (*Token, error)

Exchange Auth Code for Access Token via OAuth

func (*Auth0Provider) GetProviderName

func (p *Auth0Provider) GetProviderName() string

GetProviderName returns unique name of the provider

func (*Auth0Provider) LogoutURL

func (p *Auth0Provider) LogoutURL(returnTo string) string

LogoutURL to logout the user

func (*Auth0Provider) Refresh

func (p *Auth0Provider) Refresh(ctx context.Context, refreshToken string) (*Token, error)

Refresh gets new Access Token via OAuth.

type Config

type Config struct {
	Provider string      `envconfig:"PROVIDER" env:"PROVIDER" default:"generic"` // value which comes from the device during the sign-up ("apn")
	OAuth2   OAuthConfig `envconfig:"OAUTH" env:"OAUTH"`
}

Config general configuration

type Endpoint

type Endpoint struct {
	AuthURL  string `envconfig:"AUTH_URL" env:"AUTH_URL"`
	TokenURL string `envconfig:"TOKEN_URL" env:"AUTH_URL"`
}

type GenericProvider

type GenericProvider struct {
	Config        Config
	OAuth2        *oauth2.Config
	NewHTTPClient func() *http.Client
}

GenericProvider configuration with new http client

func NewGenericProvider

func NewGenericProvider(config Config) *GenericProvider

NewGenericProvider creates OAuth client

func (*GenericProvider) AuthCodeURL

func (p *GenericProvider) AuthCodeURL(csrfToken string) string

AuthCodeURL returns URL for redirecting to the authentication web page

func (*GenericProvider) Exchange

func (p *GenericProvider) Exchange(ctx context.Context, authorizationProvider, authorizationCode string) (*Token, error)

Exchange Auth Code for Access Token via OAuth

func (*GenericProvider) GetProviderName

func (p *GenericProvider) GetProviderName() string

GetProviderName returns unique name of the provider

func (*GenericProvider) LogoutURL

func (p *GenericProvider) LogoutURL(returnTo string) string

LogoutURL to logout the user

func (*GenericProvider) Refresh

func (p *GenericProvider) Refresh(ctx context.Context, refreshToken string) (*Token, error)

Refresh gets new Access Token via OAuth.

type GitHubProvider

type GitHubProvider struct {
	Config          Config
	OAuth2          *oauth2.Config
	NewGithubClient func(*http.Client) *github.Client
	NewHTTPClient   func() *http.Client
}

GitHubProvider configuration with client factories

func NewGitHubProvider

func NewGitHubProvider(config Config) *GitHubProvider

NewGitHubProvider creates GitHub OAuth client

func (*GitHubProvider) AuthCodeURL

func (p *GitHubProvider) AuthCodeURL(csrfToken string) string

AuthCodeURL returns URL for redirecting to the GitHub authentication web page.

func (*GitHubProvider) Exchange

func (p *GitHubProvider) Exchange(ctx context.Context, authorizationProvider, authorizationCode string) (*Token, error)

Exchange Auth Code for Access Token via OAuth.

func (*GitHubProvider) GetProviderName

func (p *GitHubProvider) GetProviderName() string

GetProviderName returns unique name of the provider

func (*GitHubProvider) Refresh

func (p *GitHubProvider) Refresh(ctx context.Context, refreshToken string) (*Token, error)

Refresh gets new Access Token via OAuth. GitHub provides permanent AccessToken and no RefreshToken, thus refreshToken is not implemented.

type OAuthConfig

type OAuthConfig struct {
	ClientID     string   `envconfig:"CLIENT_ID" env:"CLIENT_ID"`
	ClientSecret string   `envconfig:"CLIENT_SECRET" env:"CLIENT_SECRET"`
	Scopes       []string `envconfig:"SCOPES" env:"SCOPES"`
	Endpoint     Endpoint `envconfig:"ENDPOINT" env:"ENDPOINT"`
	Audience     string   `envconfig:"AUDIENCE" env:"AUDIENCE"`
	RedirectURL  string   `envconfig:"REDIRECT_URL" env:"REDIRECT_URL"`
	AccessType   string   `envconfig:"ACCESS_TYPE" env:"ACCESS_TYPE"`
	ResponseType string   `envconfig:"RESPONSE_TYPE" env:"RESPONSE_TYPE"`
	ResponseMode string   `envconfig:"RESPONSE_MODE" env:"RESPONSE_MODE"`
}

func (OAuthConfig) AuthCodeURL

func (c OAuthConfig) AuthCodeURL(csrfToken string) string

func (OAuthConfig) ToOAuth2

func (c OAuthConfig) ToOAuth2() oauth2.Config

type Provider

type Provider = interface {
	Exchange(ctx context.Context, authorizationProvider, authorizationCode string) (*Token, error)
	Refresh(ctx context.Context, refreshToken string) (*Token, error)
	AuthCodeURL(csrfToken string) string
}

Provider defines interface for authentification against auth service

func New

func New(config Config) Provider

New creates GitHub OAuth client

type TestProvider

type TestProvider struct {
}

TestProvider basic configuration.

func NewTestProvider

func NewTestProvider() *TestProvider

NewTestProvider creates GitHub Oauth client.

func (*TestProvider) AuthCodeURL

func (p *TestProvider) AuthCodeURL(csrfToken string) string

AuthCodeURL returns URL for redirecting.

func (*TestProvider) Exchange

func (p *TestProvider) Exchange(ctx context.Context, authorizationProvider, authorizationCode string) (*Token, error)

Exchange Auth Code for Access Token via OAuth.

func (*TestProvider) GetProviderName

func (p *TestProvider) GetProviderName() string

GetProviderName provides provider name.

func (*TestProvider) HandleAccessToken

func (p *TestProvider) HandleAccessToken(ctx *fasthttp.RequestCtx)

func (*TestProvider) HandleAuthorizationCode

func (p *TestProvider) HandleAuthorizationCode(ctx *fasthttp.RequestCtx)

func (*TestProvider) HandleJWKs

func (p *TestProvider) HandleJWKs(ctx *fasthttp.RequestCtx)

func (*TestProvider) Refresh

func (p *TestProvider) Refresh(ctx context.Context, refreshToken string) (*Token, error)

Refresh gets new Access Token via OAuth.

type Token

type Token struct {
	AccessToken  string
	RefreshToken string
	Expiry       time.Time
	UserID       string
}

Token provides access tokens and their attributes.

Jump to

Keyboard shortcuts

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