mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-25 05:47:57 +02:00
lastfm: authentication
This commit is contained in:
parent
3ccbb20a9e
commit
5b8f4788f9
10 changed files with 158 additions and 15 deletions
18
cmd/auth.go
18
cmd/auth.go
|
@ -43,10 +43,6 @@ var authCmd = &cobra.Command{
|
|||
redirectURL, err := backends.BuildRedirectURL(viper.GetViper(), backend.Name())
|
||||
cobra.CheckErr(err)
|
||||
|
||||
// Start an HTTP server to listen for the response
|
||||
responseChan := make(chan auth.CodeResponse)
|
||||
auth.RunOauth2CallbackServer(*redirectURL, responseChan)
|
||||
|
||||
// The backend must provide an authentication strategy
|
||||
strategy := backend.OAuth2Strategy(redirectURL)
|
||||
|
||||
|
@ -56,14 +52,20 @@ var authCmd = &cobra.Command{
|
|||
|
||||
state := "somestate" // FIXME: Should be a random string
|
||||
// Redirect user to consent page to ask for permission specified scopes.
|
||||
url := strategy.AuthCodeURL(verifier, state)
|
||||
fmt.Printf("Visit the URL for the auth dialog: %v\n", url)
|
||||
err = browser.OpenURL(url)
|
||||
authUrl := strategy.AuthCodeURL(verifier, state)
|
||||
|
||||
// Start an HTTP server to listen for the response
|
||||
responseChan := make(chan auth.CodeResponse)
|
||||
auth.RunOauth2CallbackServer(*redirectURL, authUrl.Param, responseChan)
|
||||
|
||||
// Open the URL
|
||||
fmt.Printf("Visit the URL for the auth dialog: %v\n", authUrl.Url)
|
||||
err = browser.OpenURL(authUrl.Url)
|
||||
cobra.CheckErr(err)
|
||||
|
||||
// Retrieve the code from the authentication callback
|
||||
code := <-responseChan
|
||||
if code.State != state {
|
||||
if code.State != authUrl.State {
|
||||
cobra.CompErrorln("Error: oauth state mismatch")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue