rclone: github.com/ncw/rclone/lib/oauthutil Index | Files

package oauthutil

import "github.com/ncw/rclone/lib/oauthutil"

Index

Package Files

oauthutil.go renew.go

Constants

const (
    TitleBarRedirectURL = "urn:ietf:wg:oauth:2.0:oob"

    RedirectURL = "http://" + bindAddress + "/"

    RedirectPublicURL = "http://localhost.rclone.org:" + bindPort + "/"

    RedirectLocalhostURL = "http://localhost:" + bindPort + "/"

    AuthResponse = "" /* 752 byte string literal not displayed */

)

func Config Uses

func Config(id, name string, m configmap.Mapper, config *oauth2.Config, opts ...oauth2.AuthCodeOption) error

Config does the initial creation of the token

It may run an internal webserver to receive the results

func ConfigErrorCheck Uses

func ConfigErrorCheck(id, name string, m configmap.Mapper, errorHandler func(*http.Request) AuthError, config *oauth2.Config, opts ...oauth2.AuthCodeOption) error

ConfigErrorCheck does the same as Config, but allows the backend to pass a error handling function This function gets called with the request made to rclone as a parameter if no code was found

func ConfigNoOffline Uses

func ConfigNoOffline(id, name string, m configmap.Mapper, config *oauth2.Config, opts ...oauth2.AuthCodeOption) error

ConfigNoOffline does the same as Config but does not pass the "access_type=offline" parameter.

func Context Uses

func Context(client *http.Client) context.Context

Context returns a context with our HTTP Client baked in for oauth2

func GetToken Uses

func GetToken(name string, m configmap.Mapper) (*oauth2.Token, error)

GetToken returns the token saved in the config file under section name.

func PutToken Uses

func PutToken(name string, m configmap.Mapper, token *oauth2.Token, newSection bool) error

PutToken stores the token in the config file

This saves the config file if it changes

type AuthError Uses

type AuthError struct {
    Name        string
    Description string
    Code        string
    HelpURL     string
}

AuthError gets returned by the backend's errorHandler function

type AuthResponseData Uses

type AuthResponseData struct {
    OK   bool   // Failure or Success?
    Code string // code to paste into rclone config
    AuthError
}

AuthResponseData can fill the AuthResponse template

type Renew Uses

type Renew struct {
    // contains filtered or unexported fields
}

Renew allows tokens to be renewed on expiry if uploads are in progress.

func NewRenew Uses

func NewRenew(name string, ts *TokenSource, run func() error) *Renew

NewRenew creates a new Renew struct and starts a background process which renews the token whenever it expires. It uses the run() call to run a transaction to do this.

It will only renew the token if the number of uploads > 0

func (*Renew) Invalidate Uses

func (r *Renew) Invalidate()

Invalidate invalidates the token source

func (*Renew) Start Uses

func (r *Renew) Start()

Start should be called before starting an upload

func (*Renew) Stop Uses

func (r *Renew) Stop()

Stop should be called after finishing an upload

type TokenSource Uses

type TokenSource struct {
    // contains filtered or unexported fields
}

TokenSource stores updated tokens in the config file

func NewClient Uses

func NewClient(name string, m configmap.Mapper, oauthConfig *oauth2.Config) (*http.Client, *TokenSource, error)

NewClient gets a token from the config file and configures a Client with it. It returns the client and a TokenSource which Invalidate may need to be called on

func NewClientWithBaseClient Uses

func NewClientWithBaseClient(name string, m configmap.Mapper, config *oauth2.Config, baseClient *http.Client) (*http.Client, *TokenSource, error)

NewClientWithBaseClient gets a token from the config file and configures a Client with it. It returns the client and a TokenSource which Invalidate may need to be called on. It uses the httpClient passed in as the base client.

func (*TokenSource) Invalidate Uses

func (ts *TokenSource) Invalidate()

Invalidate invalidates the token

func (*TokenSource) OnExpiry Uses

func (ts *TokenSource) OnExpiry() <-chan time.Time

OnExpiry returns a channel which has the time written to it when the token expires. Note that there is only one channel so if attaching multiple go routines it will only signal to one of them.

func (*TokenSource) Token Uses

func (ts *TokenSource) Token() (*oauth2.Token, error)

Token returns a token or an error. Token must be safe for concurrent use by multiple goroutines. The returned Token must not be modified.

This saves the token in the config file if it has changed

Package oauthutil imports 19 packages (graph). Updated 2019-09-18. Refresh now. Tools for package owners.