auth

package
v0.0.0-...-ff244ab Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2021 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const TokenFileFmt = ".cozy-oauth-%s"

TokenFileFmt is the filename in which are stored OAuth client data and token.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	TokenType    string `json:"token_type"`
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	Scope        string `json:"scope"`
}

AccessToken describes the content of an access token

func (*AccessToken) AuthHeader

func (t *AccessToken) AuthHeader() string

AuthHeader implements the Tokener interface for the access token

func (*AccessToken) Clone

func (t *AccessToken) Clone() *AccessToken

Clone returns a new AccessToken with cloned values

func (*AccessToken) RealtimeToken

func (t *AccessToken) RealtimeToken() string

RealtimeToken implements the Tokener interface for the access token

type Client

type Client struct {
	ClientID          string   `json:"client_id,omitempty"`
	ClientSecret      string   `json:"client_secret"`
	SecretExpiresAt   int      `json:"client_secret_expires_at"`
	RegistrationToken string   `json:"registration_access_token"`
	RedirectURIs      []string `json:"redirect_uris"`
	ClientName        string   `json:"client_name"`
	ClientKind        string   `json:"client_kind,omitempty"`
	ClientURI         string   `json:"client_uri,omitempty"`
	LogoURI           string   `json:"logo_uri,omitempty"`
	PolicyURI         string   `json:"policy_uri,omitempty"`
	SoftwareID        string   `json:"software_id"`
	SoftwareVersion   string   `json:"software_version,omitempty"`
}

Client describes the data of an OAuth client

func (*Client) AuthHeader

func (c *Client) AuthHeader() string

AuthHeader implements the Tokener interface for the client

func (*Client) Clone

func (c *Client) Clone() *Client

Clone returns a new Client with cloned values

type Error

type Error struct {
	Value       string `json:"error"`
	Description string `json:"error_description,omitempty"`
}

Error represents a client registration error returned by the OAuth server

func (*Error) Error

func (e *Error) Error() string

type FileStorage

type FileStorage struct{}

FileStorage implements the Storage interface using a simple file.

func NewFileStorage

func NewFileStorage() *FileStorage

NewFileStorage creates a new *FileStorage

func (*FileStorage) Load

func (s *FileStorage) Load(domain string) (client *Client, token *AccessToken, err error)

Load reads from the OAuth file and the states stored for the specified domain.

func (*FileStorage) Save

func (s *FileStorage) Save(domain string, client *Client, token *AccessToken) error

Save writes the authentication states to a file for the specified domain.

type Request

type Request struct {
	ClientParams *Client
	Scopes       []string
	Domain       string
	Scheme       string
	HTTPClient   *http.Client
	UserAgent    string
	UserAccept   UserAcceptFunc
	Storage      Storage
	// contains filtered or unexported fields
}

Request represents an OAuth request with client parameters (*Client) and list of scopes that the application wants to access.

func (*Request) AuthCodeURL

func (r *Request) AuthCodeURL(c *Client, state string) (string, error)

AuthCodeURL returns the url on which the user is asked to authorize the application.

func (*Request) AuthHeader

func (r *Request) AuthHeader() string

AuthHeader implements the Tokener interface for the request

func (*Request) Authenticate

func (r *Request) Authenticate() error

Authenticate will start the authentication flow.

If the storage has a client and token stored, it is reused and no authentication flow is started. Otherwise, a new client is registered and the authentication process is started.

func (*Request) GetAccessToken

func (r *Request) GetAccessToken(c *Client, code string) (*AccessToken, error)

GetAccessToken fetch the access token using the specified authorization code.

func (*Request) RealtimeToken

func (r *Request) RealtimeToken() string

RealtimeToken implements the Tokener interface for the access token

func (*Request) RefreshToken

func (r *Request) RefreshToken(c *Client, t *AccessToken) (*AccessToken, error)

RefreshToken performs a token refresh using the specified client and current access token.

func (*Request) RegisterClient

func (r *Request) RegisterClient(c *Client) (*Client, error)

RegisterClient performs the registration of the specified client.

type Storage

type Storage interface {
	Load(domain string) (client *Client, token *AccessToken, err error)
	Save(domain string, client *Client, token *AccessToken) error
}

Storage is an interface to specify how to store and load authentication states.

type UserAcceptFunc

type UserAcceptFunc func(accessURL string) (*url.URL, error)

UserAcceptFunc is a function that can be defined by the user of this library to describe how to ask the user for authorizing the client to access to its data.

The method should return the url on which the user has been redirected which should contain a registering code and state, or an error .

Jump to

Keyboard shortcuts

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