MCPcopy Create free account
hub / github.com/dinofizz/diskplayer / NewToken

Function NewToken

auth.go:37–56  ·  view source on GitHub ↗

NewToken will create a new OAuth2 token request. The user will be prompted to visit a URL, and after access is granted a new OAuth2 token is returned. An error is returned if encountered.

(ds DiskplayerServer)

Source from the content-addressed store, hash-verified

35// The user will be prompted to visit a URL, and after access is granted a new OAuth2 token is returned.
36// An error is returned if encountered.
37func NewToken(ds DiskplayerServer) (*oauth2.Token, error) {
38 s, err := ds.RunCallbackServer()
39 if err != nil {
40 return nil, err
41 }
42
43 u := ds.Authenticator().AuthURL(STATE_IDENTIFIER)
44 fmt.Println("Please log in to Spotify by visiting the following page in your browser:", u)
45
46 t := <-ds.TokenChannel()
47
48 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
49 defer cancel()
50 err = s.Shutdown(ctx)
51 if err != nil {
52 return nil, err
53 }
54
55 return t, nil
56}
57
58// ReadToken will attempt to deserialize a token whose path is defined in the diskplayer.yaml
59// configuration file under the token.file_path field.

Callers 3

mainFunction · 0.92
TestNewTokenFunction · 0.85

Calls 3

RunCallbackServerMethod · 0.65
AuthenticatorMethod · 0.65
TokenChannelMethod · 0.65

Tested by 2

TestNewTokenFunction · 0.68