-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
41 lines (35 loc) · 811 Bytes
/
auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package commands
import (
"fmt"
"github.com/ambientsound/visp/api"
"github.com/ambientsound/visp/input/lexer"
spotify_proxyclient "github.com/ambientsound/visp/spotify/proxyclient"
)
// Auth runs OAuth2 authentication flow against Spotify.
type Auth struct {
command
api api.API
token string
}
func NewAuth(api api.API) Command {
return &Auth{
api: api,
}
}
// Parse implements Command.
func (cmd *Auth) Parse() error {
tok, lit := cmd.ScanIgnoreWhitespace()
if tok == lexer.TokenIdentifier {
cmd.token = lit
} else {
return fmt.Errorf("unexpected '%s'; expected token from web page", lit)
}
return cmd.ParseEnd()
}
func (cmd *Auth) Exec() error {
token, err := spotify_proxyclient.DecodeTokenString(cmd.token)
if err != nil {
return err
}
return cmd.api.Authenticate(token)
}