Auth

package
v0.0.0-...-961c423 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ENV_EVERNOTE_HOST   = "EVERNOTE_HOST"
	ENV_CONSUMER_KEY    = "EVERNOTE_API_KEY"
	ENV_CONSUMER_SECRET = "EVERNOTE_API_SECRET"
	ENV_CALLBACK_URL    = "EVERNOTE_SERVICE_CALLBACK"
	ENV_EVERNOTE_DEBUG  = "EVERNOTE_DEBUG"
)

Environment variables for configuration

View Source
const (
	REQUEST_TOKEN_URL   = "/oauth"
	AUTHORIZE_TOKEN_URL = "/OAuth.action"
	ACCESS_TOKEN_URL    = "/oauth"
)
View Source
const (
	ENV_API_KEY    = "EVERNOTE_API_KEY"
	ENV_API_SECRET = "EVERNOTE_API_SECRET"
	ENV_IS_SANDBOX = "EVERNOTE_IS_SANDBOX"
)

CONSTANTS

Variables

This section is empty.

Functions

func GetEvernoteAccessToken

func GetEvernoteAccessToken(evernoteHost string, requestToken string, requestSecret string, verifier string, isSandbox bool) (string, string, map[string]string, error)

GetEvernoteAccessToken returns the access token, the secret and any additional data. We basically decompose the oauth.AccessToken struct that is returned.

func GetEvernoteTempRequestToken

func GetEvernoteTempRequestToken(evernoteHost string, redirectUri string, isSandbox bool) (string, string, string, *oauth.Consumer, error)

GetEvernoteTempRequestToken will authenticate with Evernote and return the temporary token and the secret.

func GetOauthConsumer

func GetOauthConsumer(reqTokenUri string, authTokenUri string, accessTokenUri string, debugMode bool) *oauth.Consumer

GetOauthConsumer will return a consumer given a set of URLs

Types

type AuthStageResult

type AuthStageResult struct {
	// In case of error
	Error error
	// http.Request objects will commonly be assigned to this.
	ErrorAssocObject interface{}
	// the results are stored here. Per method basis
	Elements map[string]interface{}
}

AuthStageResult contains the result for a particular stage in the authentication process.

type BotError

type BotError struct {
	Message          string
	IsRedirect       bool
	IsInvalidLogin   bool
	IsInvalid2FACode bool
}

Our own error type

func (*BotError) Error

func (e *BotError) Error() string

type EvernoteAuthBot

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

EvernoteAuthBot will do the authentication via HTTP requests, storing state as it does so. Basically, it does the required HTTP requests as if you were logging into Evernote on the web.

func (*EvernoteAuthBot) AllowAccess

func (bot *EvernoteAuthBot) AllowAccess(tmpOauthToken string, results chan<- AuthStageResult)

func (*EvernoteAuthBot) ApiCredentials

func (bot *EvernoteAuthBot) ApiCredentials() (string, string, error)

ApiCredentials will get the API key and secret from environment variables. This library relies on environment variables to pull out

func (*EvernoteAuthBot) Cookie

func (bot *EvernoteAuthBot) Cookie(name string) *http.Cookie

Cookie returns a *http.Cookie that has a Name matching the name argument which was set in the process of authentication.

func (*EvernoteAuthBot) GetOauthToken

func (bot *EvernoteAuthBot) GetOauthToken(
	tmpOauthToken string,
	verifier string,
	results chan<- AuthStageResult,
)

func (*EvernoteAuthBot) GetTmpOauthToken

func (bot *EvernoteAuthBot) GetTmpOauthToken(results chan<- AuthStageResult)

GetTmpOauthToken will query for the initial temporary oauth token that evernote requests for the authentication process to proceed.

func (*EvernoteAuthBot) HandleTwoFactor

func (bot *EvernoteAuthBot) HandleTwoFactor(authCode string, results chan<- AuthStageResult)

HandleTwoFactor will ask user for 2FA code before proceeding to request for access

func (*EvernoteAuthBot) LoadPage

func (bot *EvernoteAuthBot) LoadPage(uri string, method string, params url.Values) (*http.Response, error)

LoadPage sends HTTP requests and does some minimal parsing of the response. At this point this means we extract the cookies. Only handles GET and POST requests as of now.

func (*EvernoteAuthBot) Login

func (bot *EvernoteAuthBot) Login(
	username string,
	password string,
	results chan<- AuthStageResult,
)

Login prompts user for credentials (including 2FA). Exits if invalid credentials provided.

func (*EvernoteAuthBot) PostData

func (bot *EvernoteAuthBot) PostData() map[string]url.Values

func (*EvernoteAuthBot) TempOauthToken

func (bot *EvernoteAuthBot) TempOauthToken() string

Jump to

Keyboard shortcuts

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