login

package
v0.0.0-...-5782047 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2021 License: GPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TokenFileName is the standard file name to save the OAuth token to
	TokenFileName = "token.json"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth interface {
	Login() *oauth2.Token
	SaveToken(string, *oauth2.Token) error
}

Auth is the interface Login implements. It supports log in to the Spotify account. You can also save the token to a file.

type Login

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

Login is the type to use when logging into a Spotify account.

func NewLogin

func NewLogin(callbackURL, clientID, clientSecret string) Login

NewLogin creates a new Login with the given callbackURL to listen on. It will also create a code verifier for this login.

func (Login) Login

func (l Login) Login() *oauth2.Token

Login wil open a http server to log in to your account to get a newly created OAuth2 token.

func (Login) SaveToken

func (l Login) SaveToken(file string, token *oauth2.Token) error

SaveToken will save access and refresh token to token.json file in exec directory.

type MockedAuth

type MockedAuth struct {
	LError bool
	SError bool
}

MockedAuth implements the Auth interface for tests.

func (MockedAuth) Login

func (l MockedAuth) Login() *oauth2.Token

Login will return a token or error.

func (MockedAuth) SaveToken

func (l MockedAuth) SaveToken(_ string, _ *oauth2.Token) error

SaveToken mocks saving the token.

type MockedResponseWriter

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

MockedResponseWriter implements http.ResponseWriter for tests

func (*MockedResponseWriter) Header

func (w *MockedResponseWriter) Header() http.Header

Header returns the HTTP header

func (*MockedResponseWriter) Write

func (w *MockedResponseWriter) Write(b []byte) (int, error)

Write writes some bytes to the body

func (*MockedResponseWriter) WriteHeader

func (w *MockedResponseWriter) WriteHeader(statusCode int)

WriteHeader sets the status code

type MockedSpotifyauthAuthenticator

type MockedSpotifyauthAuthenticator struct {
	FailToken bool
}

MockedSpotifyauthAuthenticator implements interface SpotifyAuthenticatior for tests

func (MockedSpotifyauthAuthenticator) AuthURL

AuthURL returns a URL to the the Spotify Accounts Service's OAuth2 endpoint.

func (MockedSpotifyauthAuthenticator) Client

Client creates a *http.Client that will use the specified access token for its API requests. Combine this with spotify.HTTPClientOpt.

func (MockedSpotifyauthAuthenticator) Exchange

Exchange is like Token, except it allows you to manually specify the access code instead of pulling it out of an HTTP request.

func (MockedSpotifyauthAuthenticator) Token

Token pulls an authorization code from an HTTP request and attempts to exchange it for an access token. The standard use case is to call Token from the handler that handles requests to your application's redirect URL.

type SpotifyAuthenticatior

type SpotifyAuthenticatior interface {
	AuthURL(state string, opts ...oauth2.AuthCodeOption) string
	Token(ctx context.Context, state string, r *http.Request, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
	Exchange(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
	Client(ctx context.Context, token *oauth2.Token) *http.Client
}

SpotifyAuthenticatior is an interface for spotifyauth.Authenticator

Jump to

Keyboard shortcuts

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