provider

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DeviceAccessToken = "123"
View Source
var DeviceExpiresIn = time.Minute * 60
View Source
var DeviceUserID = "1"
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   oauth.Config `envconfig:"OAUTH" env:"OAUTH"`
}

Config general configuration

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 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