digipoauth

package module
v0.0.0-...-39590b7 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: MPL-2.0 Imports: 19 Imported by: 0

README

Digiposte oauth

This go package aims to provide oauth2 endpoint for digiposte.fr. digiposte.fr is a french service provided by La Poste (the french post office) to store and share documents. It is similar to Dropbox, Google Drive, etc.

Officially, digiposte.fr does not provide any oauth2 endpoint. This package is a workaround to connect to digiposte.fr using oauth2.

Documentation

Index

Constants

View Source
const (
	// AuthorizePath is the path to the authorize endpoint.
	AuthorizePath = "/authorize"
	// TokenPath is the path to the token endpoint.
	TokenPath = "/token"

	// ReadTimeout is the timeout for reading the request.
	ReadTimeout = 5 * time.Second
	// WriteTimeout is the timeout for writing the response.
	WriteTimeout = 5 * time.Minute
)
View Source
const RefreshTokenLength = 32

Variables

View Source
var ErrNilCredentials = errors.New("nil credentials")

Functions

This section is empty.

Types

type AccessGenerator

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

AccessGenerator is an oauth2.AccessGenerate that uses a LoginMethod to generate the access token.

func (*AccessGenerator) SetCredentials

func (ag *AccessGenerator) SetCredentials(clientID string, creds *Credentials)

func (*AccessGenerator) Token

func (ag *AccessGenerator) Token(
	ctx context.Context,
	generateBasic *oauth2v4.GenerateBasic,
	isGenRefresh bool,
) (string, string, error)

type Config

type Config struct {
	Addr        string
	Server      *server.Config
	LoginMethod LoginMethod
	Logger      *log.Logger
}

type Credentials

type Credentials struct {
	Username  string
	Password  string
	OTPSecret string
}

type InvalidCredentialsError

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

func (*InvalidCredentialsError) Error

func (e *InvalidCredentialsError) Error() string

type InvalidOptionError

type InvalidOptionError struct {
	Name string
	Err  error
}

func (*InvalidOptionError) Apply

func (e *InvalidOptionError) Apply(interface{}) error

func (*InvalidOptionError) Error

func (e *InvalidOptionError) Error() string

func (*InvalidOptionError) Unwrap

func (e *InvalidOptionError) Unwrap() error

type LoginMethod

type LoginMethod interface {
	Login(ctx context.Context, creds *Credentials) (*oauth2.Token, []*http.Cookie, error)
}

LoginMethod is the method to connect to digiposte.

type LoginMethodFunc

type LoginMethodFunc func(ctx context.Context, creds *Credentials) (*oauth2.Token, []*http.Cookie, error)

func (LoginMethodFunc) Login

func (f LoginMethodFunc) Login(ctx context.Context, creds *Credentials) (*oauth2.Token, []*http.Cookie, error)

type Option

type Option interface {
	Apply(instance interface{}) error
}

type OptionFunc

type OptionFunc func(instance interface{}) error

func (OptionFunc) Apply

func (f OptionFunc) Apply(instance interface{}) error

type RequiredFieldError

type RequiredFieldError struct {
	Field string
}

func (*RequiredFieldError) Error

func (e *RequiredFieldError) Error() string

type Server

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

Server is a local web server for collecting auth.

func NewServer

func NewServer(setter digiconfig.Setter, config *Config) (*Server, error)

StartServer starts a local webserver to receive the auth.

func (*Server) AuthorizeURL

func (s *Server) AuthorizeURL() string

AuthorizeURL returns the URL to the authorize endpoint.

func (*Server) RegisterUser

func (s *Server) RegisterUser(clientID, clientSecret, redirectURL, username, password, otpSecret string) error

RegisterUser adds a user to the server.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Close closes the server.

func (*Server) Start

func (s *Server) Start() error

Start starts the server.

func (*Server) TokenURL

func (s *Server) TokenURL() string

TokenURL returns the URL to the token endpoint.

Directories

Path Synopsis
configfakes
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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