Added Remember-Token to Authenticate
Renamed Authenticate to Authenticate2 and added remember-me support Created Authenticate as wrapper for Authenticate2 for backwards compat.
This commit is contained in:
17
sessions.go
17
sessions.go
@@ -17,6 +17,7 @@ type User struct {
|
||||
type AuthData struct {
|
||||
User User `json:"user"`
|
||||
SessionToken string `json:"session-token"`
|
||||
RememberToken string `json:"remember-token"`
|
||||
}
|
||||
|
||||
type AuthResponse struct {
|
||||
@@ -25,11 +26,18 @@ type AuthResponse struct {
|
||||
}
|
||||
|
||||
// Authenticate authenticates the client with the Tastytrade API
|
||||
func (api *TastytradeAPI) Authenticate(username, password string) error {
|
||||
func (api *TastytradeAPI) Authenticate2(username, password string, remember bool) error {
|
||||
var remStr string
|
||||
if remember {
|
||||
remStr = "true"
|
||||
} else {
|
||||
remStr = "false"
|
||||
}
|
||||
authURL := fmt.Sprintf("%s/sessions", api.host)
|
||||
authData := map[string]string{
|
||||
"login": username,
|
||||
"password": password,
|
||||
"remember-me": remStr,
|
||||
}
|
||||
authBody, err := json.Marshal(authData)
|
||||
if err != nil {
|
||||
@@ -52,5 +60,12 @@ func (api *TastytradeAPI) Authenticate(username, password string) error {
|
||||
}
|
||||
|
||||
api.authToken = authResponse.Data.SessionToken
|
||||
if remember {
|
||||
api.remToken = authResponse.Data.RememberToken
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *TastytradeAPI) Authenticate(username, password string) error {
|
||||
return api.Authenticate2(username, password, false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user