Documentation ¶
Index ¶
- Constants
- type AccessToken
- type Client
- type Error
- type FileStorage
- type Request
- func (r *Request) AuthCodeURL(c *Client, state string) (string, error)
- func (r *Request) AuthHeader() string
- func (r *Request) Authenticate() error
- func (r *Request) GetAccessToken(c *Client, code string) (*AccessToken, error)
- func (r *Request) RealtimeToken() string
- func (r *Request) RefreshToken(c *Client, t *AccessToken) (*AccessToken, error)
- func (r *Request) RegisterClient(c *Client) (*Client, error)
- type Storage
- type UserAcceptFunc
Constants ¶
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 ¶
AuthHeader implements the Tokener interface for the client
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
type FileStorage ¶
type FileStorage struct{}
FileStorage implements the Storage interface using a simple file.
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 ¶
AuthCodeURL returns the url on which the user is asked to authorize the application.
func (*Request) AuthHeader ¶
AuthHeader implements the Tokener interface for the request
func (*Request) Authenticate ¶
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 ¶
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.
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 ¶
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 .