lastfm: authentication

This commit is contained in:
Philipp Wolfer 2023-11-23 23:14:47 +01:00
parent 3ccbb20a9e
commit 5b8f4788f9
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
10 changed files with 158 additions and 15 deletions

View file

@ -24,11 +24,21 @@ import (
type OAuth2Strategy interface {
Config() oauth2.Config
AuthCodeURL(verifier string, state string) string
AuthCodeURL(verifier string, state string) AuthUrl
ExchangeToken(code CodeResponse, verifier string) (*oauth2.Token, error)
}
type AuthUrl struct {
// The URL the user must visit to approve access
Url string
// Random state string passed on to the callback.
// Leave empty if the service does not support state.
State string
// Parameter name of the code passed on to the callback (usually "code")
Param string
}
type CodeResponse struct {
Code string
State string
@ -46,8 +56,13 @@ func (s StandardStrategy) Config() oauth2.Config {
return s.conf
}
func (s StandardStrategy) AuthCodeURL(verifier string, state string) string {
return s.conf.AuthCodeURL(state, oauth2.AccessTypeOffline, oauth2.S256ChallengeOption(verifier))
func (s StandardStrategy) AuthCodeURL(verifier string, state string) AuthUrl {
url := s.conf.AuthCodeURL(state, oauth2.AccessTypeOffline, oauth2.S256ChallengeOption(verifier))
return AuthUrl{
Url: url,
State: state,
Param: "code",
}
}
func (s StandardStrategy) ExchangeToken(code CodeResponse, verifier string) (*oauth2.Token, error) {