oauth2

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const AuthURL = "/authen/v1/index"

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientSource

type ClientSource interface {
	TokenSource
	Client() api.Client
}

ClientSource represents the source which provides a Client method to retrieve a Client.

type Config

type Config struct {
	// AppID is the app id of oauth2.
	AppID string

	// AppSecret is the app secret of oauth2.
	AppSecret string

	// AppTicket represents the ticket of the app.
	// It's used to retrieve the tenant access token.
	// If you're using the internal app, please leave it empty.
	AppTicket string

	// TenantKey represents the key of the tenant.
	TenantKey string

	// RedirectURL is the URL to redirect users going through
	RedirectURL string

	// Type represents the type of the app.
	Type
	// contains filtered or unexported fields
}

Config represents the configuration of the oauth2 service

func (*Config) AuthCodeURL

func (c *Config) AuthCodeURL(state string) string

AuthCodeURL is the URL to redirect users going through authentication

func (*Config) Exchange

func (c *Config) Exchange(ctx context.Context, code string) (*Token, error)

Exchange retrieve the token from access token endpoint

func (*Config) TenantTokenSource

func (c *Config) TenantTokenSource(ctx context.Context) ClientSource

TenantTokenSource returns a token source that retrieves tokens from the tenant token endpoint

func (*Config) TokenSource

func (c *Config) TokenSource(ctx context.Context, t *Token) ClientSource

TokenSource returns a TokenSource to grant token access

type Token

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

func NewToken

func NewToken(tk *authen.AccessTokenData) *Token

func (*Token) Valid

func (t *Token) Valid() bool

Valid checks if the token is still valid

type TokenSource

type TokenSource interface {
	Token() (*Token, error)
}

A TokenSource is anything that can return a token.

type Type

type Type int8
const (
	TypeLark Type = iota
	TypeFeishu
)

Jump to

Keyboard shortcuts

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